Skip to contents

Wraps 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

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 directly.

width

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

height

Plot height, in unit. Default is 8.

dpi

Resolution

device

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

unit

Units for width and height. Default "cm". Passed to ggsave.

...

Additional arguments passed to ggsave

Value

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

See also

Examples

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