This function takes a ggplot or list of ggplots and writes them to a (multipage) file. See below for details.

save_multipage(
  gg = last_plot(),
  filename,
  device = NULL,
  path = NULL,
  scale = 1,
  width = NA,
  height = NA,
  units = c("mm", "cm", "in"),
  dpi = 300,
  limitsize = TRUE,
  return_input = FALSE,
  multiple_files = FALSE,
  ...
)

Arguments

gg

A ggplot or list of ggplots

filename

File name to create on disk.

device

Device to use. Can either be a device function (e.g. png()), or one of "eps", "ps", "tex" (pictex), "pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only).

path

Path to save plot to (combined with filename).

scale

Multiplicative scaling factor.

width, height

Dimensions of the saved plot. If not specified, save_multipage() will try to infer the dimensions from the incoming ggplot object. If the incoming ggplot object has no absolute dimensions, system default device dimensions are used.

units

Unit dimensions. Defaults to "mm".

dpi

Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types.

limitsize

When TRUE (the default), ggsave will not save images larger than 50x50 inches, to prevent the common error of specifying dimensions in pixels.

return_input

Return the input ggplot or plotlist is after saving. This enables the use within dplyr pipes.

multiple_files

Save pages as individal files.

...

Other arguments passed on to the graphics device function, as specified by device.

Details

Handling of multiple pages. For a list of ggplots, each list element is rendered as a separate page into a mutipage pdf file. To save pages as individual files, use multiple_files = TRUE. For output formats that do not support multipage files (png, jpg, etc), pages are saved to individual files by default.

Handling of file dimensions. Output file dimensions are determined according the the following precedence.

  1. The width and height parameters of save_multipage().

  2. Dimensions inferred from an incoming ggplot object containing absolute dimensions.

  3. System default device dimensions.