[Rd] Support for transparency in metafile export & support for export to Powerpoint
Tom.Wenseleers at bio.kuleuven.be
Mon Jun 29 12:55:52 CEST 2015
For vector-based output, PDF export of R graphs works well, but unfortunately Office on Windows provide poor support for PDF and importing & exporting to other formats using Inkscape can be buggy.
Enhanced metafile export in turn does not support transparency (also not in package devEMF - are there any plans to support this perhaps in the future?). And rasterising graphs to a PNG I often find dissatisfactory, as vector-based graphs should ideally stay in vector format, especially when it comes to axes and axes labels etc.
So this means that by default, there are rather few good options left to export all those beautiful R graphs in high-quality vector format.
I recently discovered that package ReporteRs provides near-perfect export of R graphs in fully editable vector format to Powerpoint or Word using the Office native DrawingML format, with full upport for transparency, in a much better quality than what is provided by default in grDevices. This made me wonder if exporting a graph to Powerpoint could perhaps also be supported in grDevices?
In ReporteRs the code e.g. to export a ggplot would be
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)
mydoc = addPlot( mydoc, function( ) print( myplot ), vector.graphic=TRUE)
writeDoc( mydoc, file = "test plot.pptx" )
I was thinking it could be nice though to provide this capability also in base R - so that e.g.
File...Save as...would also provide an option to save as Powerpoint, with options for the width, height, font and font size used for export, or that there would be an extra command dev.copy2ppt or a combination of ppt ( ) and dev.off() to export to Powerpoint, using the code available in ReporteRs.
Especially for use in the classroom this would be super handy, as windows users are now pretty much tied to using bitmap-based PNG, thereby limiting the ease with which the final layout of R graphs can be edited !
Prof Tom Wenseleers
University of Leuven
3000 Leuven, Belgium
[[alternative HTML version deleted]]
More information about the R-devel