在 R 中创建具有专业外观的 Powerpoint

Creating Professional Looking Powerpoints in R

有没有什么好的方法可以使用R中的数据和ReporteRs之类的包来生成完整的Powerpoints? 我有大约 900 张幻灯片要创建。我们的分析师目前遵循这条道路:

DB --> SAS --> CSV --> PPTX(嵌入式图形)(x900 次)

这是手动的,容易出现很多错误并且速度很慢。

理想情况下,我更喜欢:

DB --> R + ReporteRs --> PPTX(x1 次)

问题有 2 个方面。首先,我们的客户(不合理地)更喜欢 PPTX 而不是 Web 甚至 PDF 格式。其次,R 图形无法在 PPTX 中编辑,并且有时不理想 sized/formatted,尤其是在轴文本大小方面。 那么有没有办法使用 R 创建可编辑的 Powerpoint 图形、超链接目录等? 如果没有,至少有 一套好的 ggplot2 模板与体面的 PPTX 演示文稿格式一起使用?

已解决。原来是“不看说明书”的严重案例。解决方案是使用 ReporteRs R 包并阅读手册。 :)


手册:

addPlot {ReporteRs}
addPlot(doc, fun, pointsize = 12, vector.graphic = F, ...)
vector.graphic  
logical scalar, if TRUE, vector graphics are produced instead of PNG images.
SVG will be produced for bsdoc objects and DrawingML instructions for docx and
pptx objects.  
DrawingML instructions offer advantage to provide editable graphics
(forms and text colors , text     contents, moving and resizing is disabled).

关键段落:[...] pptx 对象的 DrawingML 说明。 DrawingML 指令提供了 [of] 提供[ing] 可编辑图形的优势。

只需设置 vector.graphic=TRUE 即可。

我现在可以在 Powerpoint 中编辑用 R 创建的图形:图例、轴文本、所有图形符号。一切。这是圣诞节早点来!感谢 ReporteRs 的创作者!我现在可以在 3 小时内完成以前需要 300 次才能完成的工作!厉害了。

下面的完整示例:

library( ReporteRs )
require( ggplot2 )
mydoc = pptx(  )
mydoc = addSlide( mydoc, slide.layout = "Title and Content" )
mydoc = addTitle( mydoc, "Plot examples" )
myplot = qplot(Sepal.Length, Petal.Length
, data = iris, color = Species
, size = Petal.Width, alpha = I(0.7)
)
# Add titles and then 'myplot'
mydoc = addPlot( mydoc, function( ) print( myplot ), vector.graphic=TRUE)  
writeDoc( mydoc, file = "~/CustomReport.pptx" )

结果:

您可以使用我刚在 CRAN 上发布的新 export 软件包以原生 Office 矢量格式轻松导出到 Office (Word/Powerpoint),从而生成完全可编辑的图表,请参阅 https://cran.r-project.org/web/packages/export/index.htmlhttps://github.com/tomwenseleers/export

例如:

install.packages("export")
library(export)

?graph2ppt
?graph2doc

library(ggplot2)
qplot(Sepal.Length, Petal.Length, data = iris, color = Species, 
      size = Petal.Width, alpha = I(0.7))
graph2ppt(file="ggplot2_plot.pptx", width=7, height=5) 
graph2doc(file="ggplot2_plot.docx", width=7, height=5)