Skip to contents

Writes a plot through ggplot2::ggsave(). When width and height are not supplied, the plot's own recommended dimensions are used; an explicit value always overrides the recommendation.

Usage

export_plot(
  x,
  path,
  width = NULL,
  height = NULL,
  dpi = 300,
  overwrite = FALSE,
  ...
)

Arguments

x

A ggplot object, or a SimtablR object with an autoplot() method.

path

Output file path; the extension selects the device. When absent, .png is added. Supported suffixes are .png, .pdf, .svg, .jpeg, .jpg, .tiff, .tif, .bmp, .eps, .ps, .tex, .wmf, and .emf; device availability still depends on the platform.

width, height

Canvas size in inches. Default NULL, meaning the plot's recommended dimensions.

dpi

Resolution for raster devices. Default 300.

overwrite

Logical. Existing files are protected by default; pass TRUE to replace the destination explicitly.

...

Passed to ggplot2::ggsave().

Value

Invisibly returns the normalized output path.

Examples

if (FALSE) { # \dontrun{
data(epitabl)
roc(epitabl, poc_hstn_value, adjudicated_acs) |>
  export_plot(tempfile(fileext = ".png"))
} # }