R eps 导出和导入 Word 2010 [英] R eps export and import into Word 2010

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

问题描述

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

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

我正在使用 ggplot2 绘图,例如

I'm using ggplot2 plots, eg

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

即使在调用 setEPS() 之后,以下都不会产生可以成功导入的文件.

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()

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

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.

所以我的问题是:

  • 哪种 (ggsave/postscript) 设置组合允许我生成可以导入 Word 2010 的 eps 文件?
  • 如何在将 Word 文档导出为 pdf 时确保字体保持清晰?
  • 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?

更新

经过更多的调查,我在 cairo_ps 上获得了更多的运气来生成绘图.但是,导入到 Word 中时没有显示任何文本.

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

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

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.

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

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.

推荐答案

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

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 

最后的有趣内容让您注意到,到目前为止,这只是一个经过 Mac 测试的解决方案.

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

我刚刚用 R 版本 2.15.1 (2012-06-22) -- "Roasted Marshmallows": Platform: i386-pc-mingw32/i386 (32-bit) and MS Word 2007 in Win XP 对其进行了测试它奏效了.命令是插入/图片.../选择 eps 格式/选择文件.

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:除了直接使用postscript设备保存之外,还有另一种方法.带有 "eps" 模式的 savePlot 方法在 Windows 中可用(但在 Mac 中不可用).我同意这些字体不像 Mac 上显示的那样流畅,但我看不出使用 savePlot 保存和从交互式窗口使用另存为之间的质量差异.

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 调用 (.External(CsavePlot, device, filename, type, restoreConsole))

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

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