Skip to contents

Unlike dr_plot_width() (a label-count guess made before the plot exists), this measures the legend actually rendered on plot - so long label text widens the saved image even when the label count is small. Requires an open graphics device to get accurate text metrics, so it opens and closes a throwaway one around the measurement.

Usage

save_dr_plot(
  plot,
  file_prefix,
  file_format = c("png", "pdf"),
  width = NULL,
  height = 6,
  panel_width = height
)

Arguments

plot

A ggplot object, such as from plot_dr_group(). Forwarded straight to ggsave(plot = ).

file_prefix

Path to save to without an extension.

file_format

File formats to write.

width

(optional) Saved width in inches. NULL measures plot's legend and adds it to panel_width.

height

Saved height in inches.

panel_width

Width of the plot panel itself, excluding the legend, in inches. Only used when width is NULL.

Value

plot, invisibly.