Skip to content

Instantly share code, notes, and snippets.

@tomravalde
Last active October 6, 2015 08:29
Show Gist options
  • Save tomravalde/5da74fcce7a1080b8e71 to your computer and use it in GitHub Desktop.
Save tomravalde/5da74fcce7a1080b8e71 to your computer and use it in GitHub Desktop.
Demonstration of using the ReporteRs R package to convert a plot into an editable figure in PowerPoint
# Example of using the ReporteRs package to convert R plots to editable figures in PowerPoint
## Based on article at http://www.sthda.com/english/wiki/create-an-editable-graph-from-r-software
## Data
### (Data from searching Scopus for 'open data' or 'open-data')
year <- c(1995:2014)
number <- c(5, 14, 5, 3, 4, 7, 15, 16, 13, 18, 19, 28, 29, 43, 69, 148, 230, 424, 618, 759)
open_data <- data.frame(year, number)
## Plot
library(ggplot2)
plot_open_data <- ggplot(open_data, aes(year, number)) +
theme_bw() +
ylab('Number of publications') +
theme(axis.title.x = element_blank()) +
geom_point()
plot_open_data
## Conversion to PowerPoint
library('ReporteRs')
doc <- pptx()
doc <- addSlide(doc, "Two Content")
doc <- addPlot(doc, function() print(plot_open_data), vector.graphic = TRUE) # Editable vector graphic
doc <- addPlot(doc, function() print(plot_open_data), vector.graphic = FALSE) # Raster format
writeDoc(doc, file = "open-data.pptx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment