Reputation: 376
I use "ggplot2" to create beautiful plots in R. I want to distribute them; I use "ReporteRs" get them into PowerPoint.
When I do this the formatting is somehow lost (no scale ability). To keep scaleability, I use the "svglite" package to save my plot as a ".svg" file.
Now; How do I get the ".svg" file into the PowerPoint?
Upvotes: 4
Views: 4895
Reputation: 11429
With ggplot::ggsave, save the plot to .svg or .eps to include a scalable form in the powerpoint.
library(ggplot2)
ggplot(mtcars, aes(mpg, wt)) +
geom_point()
ggsave("mtcars.svg")
ggsave("mtcars.eps")
Upvotes: 0
Reputation: 8019
Just an update also with regard to support for SVG in Powerpoint: SVG is fully supported in Office 2019 as well as in the Office 365 versions of PowerPoint 2016.
Regarding rmarkdown/knitr
- you can also use that to export to Powerpoint.
And there is also the option to use my export
package, to export to Powerpoint using the correct scaling (specified width & height), as mentioned in my other answer.
Finally, there is also the possibility to export to SVG, and to use e.g. Inkscape to have it converted to EMF, which you can import in all versions of Powerpoint.
Upvotes: 1
Reputation: 8019
I just made a new package, export
, that is built on top of officer
, and which retains the correct scale by using an appropriately sized Powerpoint slide template, see
https://cran.r-project.org/web/packages/export/index.html and for demo
https://github.com/tomwenseleers/export
Typical syntax is very easy, e.g.:
install.packages("export")
library(export)
library(ggplot2)
qplot(Sepal.Length, Petal.Length, data = iris, color = Species,
size = Petal.Width, alpha = I(0.7))
graph2ppt(file="ggplot2_plot.pptx", width=6, height=5)
Output is vector format and so fully editable after you ungroup your graph in Powerpoint. You can also use it to export to Word, Excel, Latex or HTML and you can also use it to export statistical output of various R stats objects.
Upvotes: 3