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
widthis not supplied.- width
Plot width, in
unit. Derived fromheightandasp_ratiowhen 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), usesragg::agg_png()for PNG files when ragg is installed, and the ggplot2 default otherwise. Pass a device function to override.- unit
Units for
widthandheight, passed toggplot2::ggsave(). Default is"cm".- ...
Additional arguments passed to
ggplot2::ggsave().
Value
The file path of the saved plot (invisibly), as returned by
ggplot2::ggsave().
See also
Other utilities:
format_num_br(),
has_insper_fonts()
Examples
if (FALSE) { # \dontrun{
p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) +
ggplot2::geom_point() +
theme_insper()
save_insper_plot(p, tempfile(fileext = ".png"))
} # }
