On this page

Save a plot at its recommended size, at 300 dpi on a white background.

Usage

acl_save_plot(
  plot,
  filename,
  width = NULL,
  height = NULL,
  dpi = 300,
  units = "in",
  ...
)

Arguments

ArgumentDefaultDescription
plotrequired

A ggplot or patchwork object.

filenamerequired

Character. File to write; the extension chooses the format, as in ggplot2::ggsave().

widthNULL

Numeric or NULL. Width in units (inches by default). NULL takes the value of acl_figure_size().

heightNULL

Numeric or NULL. Height in units (inches by default). NULL takes the value of acl_figure_size().

dpi300

Numeric. Resolution of raster formats in dots per inch, 300 by default.

units"in"

Character. Unit of width and height, "in" (inches, the default), "cm", "mm" or "px" (pixels at dpi). Letter case does not matter.

...…

Further arguments of ggplot2::ggsave(), such as device or bg (default "white").

Value

The file name, invisibly.

Details

A width or height that is not given comes from acl_figure_size(); a given width gets the height computed for it. The extension of filename chooses the format, as in ggplot2::ggsave(), and further arguments such as device are passed to it. run_acl() and run_alscl() save the figures of output = TRUE with this function.

Examples

Run the setup before the example. Fitting examples require an R-compatible C++ toolchain; simulation and export examples may write files.

Example setup
library(ALSCL)
library(ggplot2)
library(patchwork)
data("YTF_example")
x <- YTF_example
inputs <- x[c("data.CatL", "data.wgt", "data.mat")]
dat <- x$data.CatL
a <- run_acl(x, silent = TRUE)
b <- run_alscl(x, silent = TRUE)
# Use objects defined above
acl_save_plot(plot_SSB(a, se = TRUE), tempfile(fileext = ".png"))
acl_save_plot(plot_compare_ts(a, b), tempfile(fileext = ".pdf"), width = 8)

See also

Search documentation