A thin, pipe-friendly wrapper around ggplot2::ggsave() that picks the device
from the file extension and uses presentation-friendly defaults (transparent
background, generous size). Returns the plot invisibly, so it drops into a
pipeline without breaking it.
Arguments
- plot
A ggplot object.
- path
Output path; the extension sets the format (
.png,.svg,.pdf,.jpg/.jpeg,.tiff).NULL(default) writesplot.png. A bare file name lands inezrsurvey-outputs/(created on demand); a path naming a directory ("./x.png","charts/x.png", anything absolute) is used exactly as given. See theoutput_diroption.- width, height
Size in inches. Default
8 x 4.5.- dpi
Raster resolution for PNG/JPG/TIFF. Default
300.- bg
Background fill. Default
"transparent"(matches the ezrsurvey themes); use"white"for a solid background.- ...
Passed to
ggplot2::ggsave().
Details
The device is chosen from the file extension, and the plot is returned
invisibly so the call slots into a pipeline without breaking it
(p %>% save_plot("p.png") %>% print()). Defaults suit slides: a transparent
background (matching the ezrsurvey themes) and a generous size; pass
bg = "white" for a solid background. SVG output needs the suggested
svglite package.
See also
Other save:
export_summary_xlsx(),
export_xlsx(),
save_data(),
save_output()
Examples
p <- plot_bars(calc_percentage(podracing_survey, demo_gender))
tmp <- tempfile(fileext = ".png")
save_plot(p, tmp)
file.exists(tmp)
#> [1] TRUE
