djpr_save_image: Save ggplot2 plots as static images at the right size for...

View source: R/djpr_save_image.R

djpr_save_imageR Documentation

Save ggplot2 plots as static images at the right size for DJPR PowerPoint decks.

Description

This function is a wrapper around ggplot2::ggsave(). It is designed for saving plots as static images that will be then included in a DJPR PPTX deck.

Usage

djpr_save_image(
  filename,
  object = last_plot(),
  size = c("full", "twothirds", "half", "quarter"),
  remove_title = TRUE,
  dpi = "retina"
)

Arguments

filename

name, including path and extension, of the file to be saved

object

name of the ggplot2 plot to be saved; default is the last plot, using ggplot2::last_plot()

size

size of picture. Options are: "full", "twothirds", "half" and "quarter"

remove_title

TRUE by default. When TRUE, title and subtitle will be removed from the plot before saving. If FALSE, title and subtitle are retained.

dpi

resolution of picture. Default is 'retina' which is 320 dpi.

Details

Plots can be saved in pre-defined sizes: full slide, half slide, 2/3rds slide, and 1/4 slide, to fit the DJPR-SPP PowerPoint deck template.

The function removes the plot's title and subtitle by default, as these should be added on the slide itself rather than included in the image.

Examples

## Not run: 
library(ggplot2)
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point()

djpr_save_image("test.png", p)

# Or to save an image in the right size to fill half a Powerpoint slide

djpr_save_image("test.png", p, size = "half")

## End(Not run)

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