ggtoppt: Export ggplot and base graphics to PowerPoint (.pptx)

View source: R/Untitled.R

ggtopptR Documentation

Export ggplot and base graphics to PowerPoint (.pptx)

Usage

ggtoppt(gg, export = FALSE, pptname = "exportedplots.pptx", width = 8, height = 6)

Arguments

gg

A ggplot object (first class must be "gg").

export

FALSE to keep adding plots. TRUE to create the pptx file.

pptname

Name for the pptx file.

width

Plot width.

height

Plot height.

Details

First use the function with export = FALSE to create an object (a list like object called "filename" you will see in the enviroment), with all the graphs you want to export in the same ppt (either ggplot or base graphics). Base is more complicated because it does not store plots in an object. You must create a function to make the plot. It can be combined with ggplot in the same exportation. See 'Examples'.

When you are done, run a line with export = TRUE to create a power point in the working enviroment (just "ggtoppt(export = TRUE)".

Author(s)

Valeria Rolle

Examples

# Save a plot in "plot1" object.

      plot1 <- ggplot(mpg, aes(displ, hwy)) +
                  geom_point() +
                  geom_smooth(method = "lm", formula = y ~ splines::bs(x, 3),
                  se = FALSE)

# Add the plot to "filename" object to export it later.

      ggtoppt(plot1)

# Add "plot2" to "filename"

      plot2 <- ggplot(mpg, aes(displ, hwy)) +
                  geom_point() +
                  geom_smooth(span = 0.8) +
                  facet_wrap(~drv)

# Repeat with "plot2"

      ggtoppt(plot2)

# Export it all to working directory (will be printed in Console).

      ggtoppt(asdf, export = TRUE)

# If you want to start all over again, make sure to delete "filename"
from the enviroment, if you want to add new plots to the same series, keep it.

##############################################################################

### How to export base:

# Create a function with the plot.

      plot3 <- function(){
            barplot(1:10)
      }

# Save plot in "filename".

      ggtoppt(plot3)

# Export both ggplot and one base to a pptx. ("filename" was not deleted).

      ggtoppt(asdf, export = TRUE)
      

ValeriaRolle/auxfun documentation built on June 29, 2023, 5:28 p.m.