R eps导出并导入到Word 2010中

Jam*_*mes 6 r ms-word ggplot2

我在从R导出eps文件并导入到Word 2010时遇到问题.

我正在使用ggplot2情节,例如

library(ggplot2)
p <- qplot(disp,hp,data=mtcars) + stat_smooth()
p
Run Code Online (Sandbox Code Playgroud)

即使在调用setEPS()以下任何可以成功导入的生成文件之后也是如此.

ggsave("plot.eps")

postscript("plot.eps")
print(p)
dev.off()
Run Code Online (Sandbox Code Playgroud)

奇怪的是,如果我使用GUI中的菜单使用File- > Save As- > 生成绘图Postscript,则可以正确导入.但是,当Word文档随后导出为pdf时,图形中的字体有点锯齿状.

所以我的问题是:

  • (ggsave/ postscript)设置的哪些组合允许我生成可导入Word 2010的eps文件?
  • 将Word文档导出为pdf时,如何确保字体保持清晰?

更新

经过更多的调查,我有更多的运气cairo_ps来制作地块.但是,导入Word时不会显示任何文本.

此外,在乳胶文档中检查各种eps输出(cairo_ps从GUI中保存ggsave)后,似乎Word中的eps导入过滤器非常差,因为打印/ pdf输出与乳胶文档的质量不匹配.该ggsave版本(使用postscript)确实有一些颜色问题,但其他两种方法没有.

结论是这是一个Word问题,因此fortune(109)不适用.我很乐意以其他方式证明,但我会将答案和赏金奖励给能够提供命令的人,这些命令可以在命令格式中复制GUI的输出.

42-*_*42- 4

这对我有用...遵循postscript帮助页面中的建议:

 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 
Run Code Online (Sandbox Code Playgroud)

最后有趣的事情让你注意到这只是一个经过 Mac 测试的解决方案,无论如何。

编辑:我刚刚用 R 版本 2.15.1 (2012-06-22) --“烤棉花糖”测试了它:平台:i386-pc-mingw32/i386(32 位)和 Win XP 中的 MS Word 2007,它有效。命令为插入/图片.../选择 eps 格式/选择文件。

Edit2:除了直接使用postscript设备之外,还有另一种保存方法。具有模式的 savePlot 方法"eps"在 Windows 中可用(但在 Mac 中不可用)。我同意字体不像 Mac 上显示的那么平滑,但我可以看出使用 savePlot 保存和使用交互式窗口中的“另存为”在质量上没有差异。

savePlot(filename = "Rplot2", type = "eps", device = dev.cur(), restoreConsole = TRUE)
Run Code Online (Sandbox Code Playgroud)

savePlot来电(.External(CsavePlot, device, filename, type, restoreConsole))