Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

package - Creating Professional Looking Powerpoints in R

Is there a good way to use data from R and a package like ReporteRs to generate complete Powerpoints? I have about 900 slides to create. Our analysts currently follow this path:

DB --> SAS --> CSV --> PPTX (embedded graphics) (x900 times)

This is manual, open to lots of errors and slow.

Ideally, I would prefer:

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

The issue is 2-fold. First, our clients (unreasonably) prefer PPTX over a web or even PDF format. Second, R graphics cannot be edited in PPTX, and are sometimes not ideally sized/formatted, especially in terms of axis text sizes. So is there a way to use R to create editable Powerpoint graphics, hyperlinked tables of contents, etc? If not that, is there at least a good set of ggplot2 templates to use with decent PPTX presentation formatting?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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: enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...