2015-10-05 61 views
0

这可能是重复的,但我找不到GoogleStack Overflow上的Questions that may already have your answer功能的类似帖子。使用R创建清晰或清晰的图形以导入到PowerPoint中

我不确定用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() 
+0

如果你建立R中降价的[R脚本,你可以在knitr选项中设置'fig.retina = 2',它会做所有的点大小(等)为你加工。如果您将代码块命名得很好,您也可以获得很好的文件名。 – hrbrmstr

+0

@hrbrmstr我不熟悉'R Markdown'。这是一个类似'R Studio'的GUI吗?也许它是'R Studio'的一部分? –

+0

https://cran.rstudio.com/web/packages/rmarkdown/index.html – hrbrmstr

回答

0

这里是R代码创建,这似乎与Inkscape创建一个SVG文件同样清脆的文件。不需要中间编辑TIFF文件。只需将R创建的TIFF文件直接导入PowerPoint即可。

tiff(file = "example_tiff_plot_Oct5_2015.tiff", 
    compression= "lzw", width = 8, height = 6, res = 500, unit = "in", pointsize = 12) 

    plot(a, b, bty = "l") 
    title('Example Tiff Plot') 

dev.off() 

这是另一种有人向我推荐的方法。从这个png方法得到的文件尺寸比TIFF文件小,我想可能会更好地重新调整。

a <- seq(1,20) 
b <- a^0.25 

png(file = "example_png_plot_Oct6_2015.png", 
    width = 8, height = 6, res = 500, unit = "in", pointsize = 12) 

    plot(a, b, bty = "l") 
    title('Example Png Plot') 

dev.off() 
1

你可以看一下包ReporteRs

library(ReporteRs) 

my_graph_fun <- function(){ 
    a <- seq(1,20) 
    b <- a^0.25 
    plot(a, b, bty = "l") 
} 

doc = pptx() 
doc = addSlide(doc, "Title and Content") 
doc = addPlot(doc, fun = my_graph_fun) 
writeDoc(doc, "example.pptx")