djpr_save_pptx: Export a ggplot to a DJPR SPP PowerPoint slide.

View source: R/djpr_save_pptx.R

djpr_save_pptxR Documentation

Export a ggplot to a DJPR SPP PowerPoint slide.

Description

The exported slide will use the SPP template. All text is editable on the slide. Users can choose from several slide formats.

Usage

djpr_save_pptx(
  destination = NULL,
  plot = ggplot2::last_plot(),
  layout = c("full", "half", "twothirds"),
  signpost = NULL
)

Arguments

destination

The destination for the slide. Can be one of:

  • NULL (default): The slide will be kept in-memory and returned for further manipulation.

  • character: File path to save the slide to, including extension, such as "output.pptx".

  • A rpptx object: An in-memory slide pack to append to.

plot

The ggplot to turn into a slide. Default is ggplot2::last_plot().

layout

Slide layout to use. Options are "full", "half", and "twothirds". The layouts refer to the proportion of the slide width taken up by the chart.

signpost

Signpost heading, if required. If NULL (the default), no signpost will be included.

Details

For plot layouts other than 'full', you can add dot points in the sidebar of the plot using labs(sidebar = c("Dot point 1", "Dot point 2")).

Value

If destination is NULL or a pptx object, returns the updated presentation ready for further changes. Otherwise, the return value is undefined (and may change in future) since the function saves the slide to a file.

Examples

## Not run: 
library(ggplot2)
# First, create a ggplot2 object
the_ggplot <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  labs(
    title = "Chart title",
    subtitle = "Chart subtitle",
    caption = "Notes and source information."
  )

# Export `the_ggplot` to file `output.pptx`
djpr_save_pptx("output.pptx", the_ggplot)

# Specify layout and signpost
djpr_save_pptx("output.pptx", the_ggplot, layout = "half", signpost = "section")

# For slide layouts other than 'full', you can add text commentary in the
# sidebar of the slide, ike this:

the_ggplot_with_sidebar <- the_ggplot +
  labs(sidebar = c("These are some comments", "For the sidebar of the slide"))

djpr_save_pptx("output.pptx", the_ggplot_with_sidebar, layout = "twothirds")

# Export multiple slides. Different plots can be passed in for each slide.
djpr_save_pptx(NULL, the_ggplot) %>%
  djpr_save_pptx(the_ggplot, layout="half") %>%
  print(target="slidepack.pptx")

## End(Not run)

djpr-data/djprtheme documentation built on April 15, 2023, 2:47 a.m.