A convenience wrapper around ggplot2::ggsave() with sensible defaults for
figures in papers and reports: a moderate size, 300 dpi, and the output
directory created if needed. The device is inferred from the file extension.
Usage
save_plot(
filename,
plot = ggplot2::last_plot(),
width = 7,
height = 4.5,
units = "in",
dpi = 300,
...
)Arguments
- filename
Output file path. The extension sets the device (e.g.
.png,.pdf,.tiff).- plot
The plot to save; defaults to the last plot drawn.
- width, height
Dimensions.
- units
Units for
widthandheight.- dpi
Resolution for raster devices.
- ...
Passed to
ggplot2::ggsave().
Examples
p <- scatter_trend(crop_yield, fertiliser, yield)
tmp <- file.path(tempdir(), "yield.png")
save_plot(tmp, p)
