| save_figure | R Documentation |
Saves a ggplot2 plot or base R graphics to the configured figures directory. The directory is created lazily on first use.
save_figure(
plot = NULL,
name,
format = "png",
width = 8,
height = 6,
dpi = 300,
public = FALSE,
overwrite = TRUE,
...
)
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 |
The path to the saved file (invisibly)
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.