Skip to contents

Save a ggplot to disk in multiple formats and resolutions. By default, raster formats are saved at both 300 and 600 dpi.

Usage

sm_export_figure(
  plot,
  path,
  format = c("png", "pdf", "svg", "tiff", "eps"),
  dpi = c(300, 600),
  width = 7,
  height = 5,
  units = c("in", "cm", "mm"),
  background = c("white", "transparent"),
  multi_dpi = TRUE
)

Arguments

plot

A ggplot object.

path

Output file path (extension determines format if format not specified).

format

Output format.

dpi

Resolution for raster formats.

width

Plot width.

height

Plot height.

units

Size units.

background

Background colour.

multi_dpi

Logical; write both 300 and 600 dpi versions for raster formats?

Value

Character vector of paths actually written, invisibly.

Examples

corpus <- sm_example_corpus(n_works = 20)
p <- sm_plot_production(corpus)
path <- tempfile(fileext = ".png")
sm_export_figure(p, path, multi_dpi = FALSE)
#>  Saved figure to: /tmp/RtmpIQMgiF/file237042337c62.png