ggplot2:使用内置字体将图另存为EPS

Tor*_*von 5 fonts r ggplot2

一家期刊希望我将这些数字作为EPS文件提交。使用ggplot2将它们从R导出为EPS文件,然后在Adobe Illustrator中打开EPS文件,这告诉我“系统上找不到字体”。

我该如何解决这个问题?这是我当前使用的语法。

library(ggplot2)    
a <-c("Sad Mood", "Cognition", "Fatigue", "Interest Loss", "Slowed", "Self-blame", "Suicidal Ideation", "Early insomnia", "Appetite", "Late insomnia", "Agitated", "Weight", "Middle insomnia", "Hypersomnia", "Age", "Sex")
b <-c(20.7,16.5,13.8,13.1,8.8,6.4,6.1,3.6,3.0,2.5,2.1,1.3,0.9,0.7,0.4,0.1)
c <-c(17.90,13.64,11.36,10.72,6.99,4.60,4.68,2.38,2.09,1.65,1.35,0.76,0.47,0.24,0.15,0.03) #lower CI
d <-c(23.47,19.27,16.28,15.74,10.64,8.20,7.95,5.07,4.21,3.63,2.99,2.22,1.59,1.62,0.95,0.31) #upper CI

data <- data.frame(a,b,c,d)
data1 <- transform(data, a = reorder(a, order(b, decreasing = FALSE)))
data1$label <-sprintf("%.1f", data1$b)

ggplot(data1, aes(x=as.factor(a), y=b, order=a))+
  geom_bar(stat="identity",fill='#888888',colour='#888888') +theme_bw() +coord_flip() +
  ylab("Relative importance estimation in %") +xlab("") +
  geom_errorbar(aes(ymin=c, ymax=d), width=.3, size=.5)+ 
  geom_text(aes(label=label), size=4.5, vjust=.4,hjust=-1.5)+
  scale_y_continuous(limits = c(-0, 25))+
  theme(axis.text.x = element_text(size = 13))+
  theme(axis.text.y = element_text(size = 13))+
  theme(axis.title.x = element_text(size = 14, vjust=-.2)) 
Run Code Online (Sandbox Code Playgroud)

Ada*_*and 0

有一个名为extrafont的 R 包,我过去用它来解决这样的问题。是我使用的解决方案。

基本上,有一个 R 将使用的字体数据库和一个 postscript 将使用的字体数据库。大多数时候,您不必执行我上面第 12-27 行所做的操作,但如果您的字体采用非标准命名方案,则必须手动编辑 R 的字体数据库。

您的主要问题是确保 R 和 PS 中的字体名称(和字体系列名称)相同。您应该能够通过安装 extrafont(第一次安装它会在 R 中构建字体数据库)并使用正确的设备加载字体来做到这一点。