Creating Professional Looking Powerpoints in R

a 夏天 提交于 2019-11-28 04:46:11

You can use my new export package that just came out on CRAN to easily export to Office (Word/Powerpoint) in native Office vector format, resulting in fully editable graphs, see https://cran.r-project.org/web/packages/export/index.html and https://github.com/tomwenseleers/export

For example:

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) 

Solved. Turned out to be a severe case of "Not Reading the Manual." The solution is to use the ReporteRs R package AND read the manual. :)


The Manual:

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

The key paragraph: DrawingML instructions for [...] pptx objects. DrawingML instructions offer [the] advantage [of] provid[ing] editable graphics.

So simply set vector.graphic=TRUE and you're set.

I am now able in Powerpoint to edit graphics created in R: legends, axis text, all graphical symbols. Everything. This is Xmass come early! Thank you ReporteRs creators! I can now do in 3 hours what would have taken 300 before! Amazing.

Full worked out example below:

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

Result:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!