R eps导出并导入到Word 2010中 [英] R eps export and import into Word 2010

查看:296
本文介绍了R eps导出并导入到Word 2010中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从R中导出eps文件并导入到Word 2010中。



我正在使用 ggplot2

  library(ggplot2)
p < - qplot(disp,hp,data = mtcars) )+ stat_smooth()
p

即使调用 setEPS()

> ggsave(plot.eps )

postscript(plot.eps)
print(p)
dev.off()

奇怪的是,如果我使用 File - > 另存为 - > Postscript 从GUI中的菜单中,它可以正确导入。但是,当Word文档随后以PDF格式导出时,图形中的字体有点锯齿。



所以我的问题是:


  • ggsave / postscript )设置的组合允许我生成可导入到Word 2010中的EPS文件?

  • 如何在Word文档导出为PDF格式时确保字体保持清晰?



更新

经过更多调查, c $ c> cairo_ps 来生成图。然而,当输入到Word中时,没有文本显示出来。



此外,在检查各种eps输出( cairo_ps )后,保存在一个乳胶文档的GUI中, ggsave ),看起来像Word中的eps导入过滤器相当差,因为print / pdf输出不符合latex'd文件。使用 ggsave 版本(使用 postscript )确实存在一些其他两种方法没有的颜色问题。



结论是这是一个Word问题,因此 fortune(109)不适用。我很乐意被证明,但我会将答案和奖金授予谁可以提供命令的人员,这些命令可以通过命令形式复制GUI的输出。

解决方案

这适用于我......在 postscript 帮助页面中提供以下建议:

  postscript(RPlot.eps,height = 4,width = 4,horizo​​ntal = FALSE,onefile = FALSE,
paper =special)
library(ggplot2)
p < - qplot(disp,hp,data = mtcars)+ stat_smooth()
p
#geom_smooth:method =auto并且最大组的大小是< 1000,所以使用黄土。使用'method = x'来改变平滑方法。
#警告消息:
#In grid.Call.graphics(L_polygon,x $ x,x $ y,index):
#此设备不支持半透明度:仅报告每页一次
dev.off()
#quartz
#2



最后有趣的东西让你注意到,到目前为止,这只是一个经过Mac测试的解决方案。


编辑:我刚刚测试了R版本2.15.1(2012-06-22) - 烤棉花糖:平台:i386-pc-mingw32 / i386 (32位)和MS Word 2007在Win XP中运行。命令是Insert / Picture ... /选择eps格式/选择文件。



Edit2:除了直接使用postscript设备之外,还有另一种保存方法。具有eps模式的savePlot方法在Windows中可用(但在Mac中不可用)。我同意字体不像Mac上显示的那样流畅,但是我可以在使用savePlot进行保存和从交互式窗口中使用save之间识别质量方面没有差异。

  savePlot(filename =Rplot2,type =eps,device = dev.cur(),restoreConsole = TRUE)


savePlot 调用(。External(CsavePlot,device,filename,type,restoreConsole) )


I'm having trouble with exporting eps files from R and importing into Word 2010.

I'm using ggplot2 plots, eg

library(ggplot2)
p <- qplot(disp,hp,data=mtcars) + stat_smooth()
p

Even after calling setEPS() neither of the following produce files which can be successfully imported.

ggsave("plot.eps")

postscript("plot.eps")
print(p)
dev.off()

The strange thing is that if I produce the plot using File -> Save As -> Postscript from the menu in the GUI, it can be imported correctly. However, when the Word document is subsequently exported as a pdf, the fonts in the graphic are a little jagged.

So my questions are:

  • What combination of (ggsave/postscript) settings allows me to produce eps files that can be imported into Word 2010?
  • How can I ensure the fonts remain clear when the Word document is exported as a pdf?

Update

After more investigation I have had more luck with cairo_ps to produce the plots. However, no text shows up when imported into Word.

Furthermore, after checking the various eps outputs (cairo_ps, save from the GUI, ggsave) in a latex document, it seems like the eps import filter in Word quite poor as the printed/pdf output doesn't match the quality of the latex'd document. The ggsave version (which uses postscript) did have some issues with colours that the other two methods didn't have though.

The conclusion is that this is a Word issue and therefore fortune(109) does not apply. I'd be happy to be proven otherwise, but I'll award the answer and the bounty to whoever can provide the commands that can replicate the output from the GUI in command form.

解决方案

This worked for me... following advice in the postscript help page:

 postscript("RPlot.eps", height = 4, width = 4, horizontal = FALSE, onefile = FALSE,
             paper = "special")
 library(ggplot2)
 p <- qplot(disp,hp,data=mtcars) + stat_smooth()
 p
#geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to #change the smoothing method.
#Warning message:
#In grid.Call.graphics(L_polygon, x$x, x$y, index) :
#  semi-transparency is not supported on this device: reported only once per page
 dev.off()
#quartz 
#     2 

The funny stuff at the end puts you on notice that this is only a Mac-tested solution, so far anyway.

Edit: I just tested it with R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows": Platform: i386-pc-mingw32/i386 (32-bit) and MS Word 2007 in Win XP and it worked. Commands were Insert/Picture.../select eps format/select file.

Edit2: There is another method for saving besides directly using the postscript device. The savePlot method with an "eps" mode is available in Windows (but not in the Mac). I agree that the fonts are not as smooth as they appear on a Mac but I can discern no difference in quality between saving with savePlot and using save as from an interactive window.

savePlot(filename = "Rplot2", type = "eps", device = dev.cur(), restoreConsole = TRUE)

savePlot calls (.External(CsavePlot, device, filename, type, restoreConsole))

这篇关于R eps导出并导入到Word 2010中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆