Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R ggplot2:使用嵌入字体将绘图另存为EPS_R_Fonts_Ggplot2 - Fatal编程技术网

R ggplot2:使用嵌入字体将绘图另存为EPS

R ggplot2:使用嵌入字体将绘图另存为EPS,r,fonts,ggplot2,R,Fonts,Ggplot2,一家杂志希望我将这些数据作为EPS文件提交。使用ggplot2将它们作为EPS文件从R导出,然后在Adobe Illustrator中打开EPS文件,告诉我“系统上找不到字体” 我该如何解决这个问题?下面是我目前使用的语法 library(ggplot2) a <-c("Sad Mood", "Cognition", "Fatigue", "Interest Loss", "Slowed", "Self-blame", "Suicidal Ideation", "Early ins

一家杂志希望我将这些数据作为EPS文件提交。使用ggplot2将它们作为EPS文件从R导出,然后在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)) 
库(ggplot2)

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

基本上,R将使用字体数据库,postscript将使用字体数据库。大多数情况下,你不必像我在上面第12-27行所做的那样,但是如果你有一种非标准命名方案的字体,你必须手动编辑R的字体数据库


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

这是我在发布此文章之前在谷歌上找到的解决方案;然而,它是PDF格式的,不是EPS格式的,我无法让它与我的脚本一起工作。“loadfonts(device=“pdf”);loadfonts(device=“postscript”)”的确切用途是什么?安装extrafont并查看文档可能会更好,b/c我几个月前就这样做了。:)但是loadfonts会将字体注册到指定的设备(例如
pdf
postscript
)。在这种情况下,我们可以在R中指定字体,然后使用extrafont在PS中注册它。这样可以避免字体不可见的问题。如果没有,则必须确保字体名称和族名称完全匹配,如果字体族带有空格+ggplot2,则这很糟糕。对不起,我记不清了。