Saving Work
save_figure()
Save a figure to the outputs directory
Saves a ggplot2 plot or base R graphics to the configured figures directory. The directory is created lazily on first use.
Usage
save_figure( plot = NULL, name, format = "png", width = 8, height = 6, dpi = 300, public = FALSE, overwrite = TRUE, ... )
Arguments
- plot
- A ggplot2 object, or NULL to save the current plot
- name
- The name for the output file (without extension)
- format
- Output format: "png" (default), "pdf", "svg", or "jpg"
- width
- Width in inches (default: 8)
- height
- Height in inches (default: 6)
- dpi
- Resolution in dots per inch (default: 300)
- public
- If TRUE, saves to public outputs directory (for project_sensitive type)
- overwrite
- If TRUE, overwrites existing files (default: TRUE)
- ...
- Additional arguments passed to ggsave or the graphics device
Value
The path to the saved file (invisibly)
Examples
if (FALSE) {
# Save a ggplot
p <- ggplot(mtcars, aes(mpg, hp)) + geom_point()
save_figure(p, "mpg_vs_hp")
# Save as PDF for publication
save_figure(p, "mpg_vs_hp", format = "pdf", width = 10, height = 8)
# Save to public directory
save_figure(p, "summary_plot", public = TRUE)
}