Skip to contents

Export any ggplot2, gridExtra, or any plot object created with R into rendered png or jpg file.

Usage

export_plot(
  p,
  name = "plot",
  vars = NA,
  sep = ".vs.",
  width = 8,
  height = 6,
  format = "png",
  res = 300,
  dir = getwd(),
  subdir = NA,
  quiet = FALSE
)

Arguments

p

Plot object. Plot to render and export.

name

Character. File's name or suffix if vars is not NA. No need to include file format on file name.

vars

Vector. Variable names to identify by filename.

sep

Character. Separator for vars.

width, height, res

Numeric. Plot's width, height, and res (for grids).

format

Character. One of: png or jpeg.

dir, subdir

Character. In which directory/subdirectory do you wish to save the plot? Working directory as default dir.

quiet

Boolean. Display successful message with filename when saved?

Value

No return value, called for side effects.

Examples

p <- noPlot()
export_plot(p, name = "noplot", width = 10, height = 8, res = 300, dir = tempdir())
#> Plot saved as /tmp/RtmpXCMY0m/noplot.png
export_plot(p, name = "noplot2", subdir = "newplots", dir = tempdir())
#> Plot saved as /tmp/RtmpXCMY0m/newplots/noplot2.png