【发布时间】:2015-10-09 15:42:28
【问题描述】:
这可能是重复的,虽然我找不到与Google 或通过Stack Overflow 上的Questions that may already have your answer 功能类似的帖子。
我不确定使用 R 创建清晰或锐利图形的最佳方法,然后可以将其导入到,例如 PowerPoint。
以下是创建PDF 文件的代码。导入到PowerPoint 时,生成的图像非常模糊且质量非常差。
接下来,我将展示使用 Cairo 包创建漂亮清晰图像的代码和说明。但是,这涉及将生成的文件导入名为Inkscape 的第三方软件,并在将文件导入PowerPoint 之前将文件保存为新格式。
有没有一种无需将文件导入第三方软件的中间步骤即可创建漂亮清晰的图形的方法?
感谢您的任何建议。抱歉,如果这是重复的。代码如下:
setwd('c:/users/markm/simple R programs/')
a <- seq(1,20)
b <- a^0.25
plot(a, b, bty = "l")
pdf("example_pdf_plot_Oct5_2015.pdf")
plot(a, b, bty = "l")
title('Example PDF Plot')
dev.off()
#
# After creating the file below with the Cairo package:
#
# 1. Install the free software 'Inkscape'
# 2. Open the *.svg file with Inkscape and save as a *.emf file.
# 2b. Click 'OK' when asked to convert texts to paths.
# 2c. Click 'Close without saving'
# 3. Import the *.emf file into PowerPoint as a picture.
# 4. Resize and position image in PowerPoint to taste.
#
# install.packages('Cairo')
library(Cairo)
CairoSVG('example_svg_plot_Oct5_2015.svg', onefile = TRUE, pointsize = 12, width=8, height=6, bg="white")
plot(a, b, bty = "l")
title('Example SVG Plot')
dev.off()
【问题讨论】:
-
如果您在 R Markdown 中构建您的 R 脚本,您可以在 knitr 选项中设置
fig.retina=2,它会为您完成所有的点大小(等)机制。如果你很好地命名代码块,你也会得到好的文件名。 -
@hrbrmstr 我不熟悉
R Markdown。那是像R Studio这样的图形用户界面吗?也许它是R Studio的一部分? -
@hrbmstr: fig.retina=2 也是 LaTeX 中的命令吗?我正在尝试使用 .Rnw 脚本提高 .png 文件的质量。