Skip to contents

Plot themes control text and visual styling, but cannot control the physical size of a graphics device. Each bulkMAE plot_*() helper therefore attaches a recommended width and height in centimetres to its otherwise standard ggplot object. plot_save() reads that recommendation and delegates to ggplot2::ggsave() with scale = 1 by default. Explicit width or height values override either recommendation.

Usage

plot_save(
  filename,
  plot,
  width = NULL,
  height = NULL,
  units = c("cm", "in", "mm"),
  dpi = 300,
  scale = 1,
  device = NULL,
  bg = NULL,
  ...
)

Arguments

filename

Output file name, including an extension understood by ggplot2::ggsave().

plot

A ggplot object. Plots not produced by bulkMAE must supply both width and height.

width, height

Optional positive physical dimensions. When omitted, use the recommendation attached by a bulkMAE plotting helper.

units

Physical units for width and height.

dpi

Raster resolution passed to ggplot2::ggsave().

scale

Multiplicative scale passed to ggplot2::ggsave(). Keep the default of one when exact final dimensions matter.

device

Optional graphics device. When NULL, infer it from filename, with Cairo PDF preferred when available.

bg

Background colour passed to ggplot2::ggsave().

...

Additional arguments passed to ggplot2::ggsave().

Value

filename, invisibly.

Details

PDF output uses grDevices::cairo_pdf() automatically when Cairo graphics are available. Dimensions remain attached after ordinary ggplot2 + operations, so themes, labels, and scales can be changed before saving.

The RStudio plot pane and knitr graphics chunks create their graphics devices before a plot is drawn, so they do not consume the attached recommendation. Use plot_save() for an exact final output size; set fig.width and fig.height separately when a rendered document must use a particular preview size.