Skip to contents

Wraps ggplot2::ggsave() with defaults for Insper-branded output: dimensions in centimeters, a golden-ratio aspect, and the ragg device for PNG files.

Usage

save_insper_plot(
  plot,
  filename,
  asp_ratio = 1.618,
  width = height * asp_ratio,
  height = 8,
  dpi = 300,
  device = NULL,
  unit = "cm",
  ...
)

Arguments

plot

A ggplot object.

filename

File name.

asp_ratio

Aspect ratio (width / height). Default is the golden ratio (1.618). Used only when width is not supplied.

width

Plot width, in unit. Derived from height and asp_ratio when not supplied.

height

Plot height, in unit. Default is 8.

dpi

Resolution in dots per inch. Default is 300.

device

Graphics device. If NULL (default), uses ragg::agg_png() for PNG files when ragg is installed, and the ggplot2 default otherwise. Pass a device function to override.

unit

Units for width and height, passed to ggplot2::ggsave(). Default is "cm".

...

Additional arguments passed to ggplot2::ggsave().

Value

The file path of the saved plot (invisibly), as returned by ggplot2::ggsave().

Examples

if (FALSE) { # \dontrun{
p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) +
  ggplot2::geom_point() +
  theme_insper()
save_insper_plot(p, tempfile(fileext = ".png"))
} # }