Enhanced ggsave with institutional defaults and ragg device support
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
widthis not supplied directly.- width
Plot width in inches
- height
Plot height in inches
- dpi
Resolution
- device
Graphics device to use. If NULL (default), automatically uses ragg::agg_png() for PNG files when ragg is installed, otherwise falls back to ggplot2 defaults. You can override by passing a device function.
- unit
Units for
widthandheight. Default"cm". Passed toggsave.- ...
Additional arguments passed to ggsave
Value
The file path of the saved plot (invisibly), as returned by
ggsave.
Details
This function automatically uses the ragg device for PNG output when available, which provides better font rendering and eliminates DPI issues. Install the ragg package and set the RStudio backend to AGG for best results.
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"))
} # }
