Saves a ggplot2 plot at publication-ready resolution with white background.
Usage
save_fig(plot, filename, path, width = 7, height = 5, dpi = 600)
Arguments
- plot
A ggplot2 object.
- filename
Character. Output filename (e.g., "fig1_mscc.png").
- path
Character. Output directory.
- width
Numeric. Figure width in inches. Default 7.
- height
Numeric. Figure height in inches. Default 5.
- dpi
Integer. Resolution. Default 600.
Value
Character. Full path to saved file (invisible).
Examples
p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point()
out <- save_fig(p, "test_plot.png", tempdir(), width = 3, height = 2,
dpi = 72)
#> ✔ Figure saved: /tmp/Rtmp5ydOUY/test_plot.png
file.exists(out)
#> [1] TRUE
unlink(out)