R无法识别GhostScript以嵌入eps图形

5

我正在尝试嵌入一个.eps文件以满足期刊出版要求。

我使用ggplot2创建了我的图表:

p=ggplot(data=sim, aes(x=TIME,y=DV,group=ID))+
  theme_few()+
  geom_point(aes(shape=as.factor(SEASON2)),size=3,fill="white")+
  geom_point(aes(color=as.factor(AGE2),shape=as.factor(SEASON2)),size=3,fill="white",show_guide=F)+
  scale_shape_manual(name="Season",values=c(25,24))+
  geom_line(aes(color=as.factor(AGE2),linetype=as.factor(MODEL2)),size=0.75)+
  scale_linetype_manual(name="Model [Population]",values=c("dotted","solid"))+
  scale_color_manual(name="Age",values=as.vector(c(ggthemes_data$few$medium[5],ggthemes_data$few$medium[4])))+
  theme(legend.position="bottom",legend.direction="vertical",legend.box="horizontal")+
  guides(color=guide_legend(order=1), shape=guide_legend(order=2), linetype=guide_legend(order=3))+
  xlab("Clock time [hours]")+
  ylab("Testosterone levels [ng/dL]")+
  geom_hline(yintercept=300,linetype="dashed",color="black")
print(p)

然后,我生成了 .eps 文件

postscript(file.path(directory,"Script","Figure5.eps"),
           width=10,
           height=12.25,
           paper="a4",
           horizontal=T,
           onefile=TRUE)
print(p)
dev.off()

当我试图提交绘图时,该.eps文件未被在线申请接受,因为我必须将字体提供给ADQ Advisor。

为了解决这个问题,我使用了以下方法:

install.packages("extrafont")
library("extrafont")
font_import()
fonts()
loadfonts(device = "postscript") ## for postscript()

embed_fonts("./Figure5.eps", outfile = "./Figure5-embed.eps", options = "-dEPSCrop")

embedFonts(file="Figure5.eps",
          outfile="Figure5EMB.eps",
          options="-dEPSCrop")

这两个函数都失败了,并且给了我以下错误:

Error in embedFonts(file = "Figure5.eps", outfile = "Figure5EMB.eps", : GhostScript was not found

我已经在以下路径安装了GhostScript 9.18:C:\Program Files (x86)\gs\gs9.18

有什么建议吗?

1个回答

3
根据R的文档,您可以使用环境变量R_GSCMD设置Ghostscript可执行文件的位置,如果未设置则搜索PATH。您是否已经设置了该环境变量或者将Ghostscript可执行文件的路径添加到了PATH环境变量中?请注意这个此文档。我不知道为什么文档认为有不同的可执行文件来查看和操作PostScript/PDF文件,这是不正确的(尽管可能您想要使用不同的应用程序,如GSView来查看文件,但Ghostscript显示设备也可以,尽管相对较粗糙)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接