save_ggplot | R Documentation |
Saves a ggplot object just like ggplot2::ggsave()
. If the plot
has a canvas()
specified, these canvas parameters are used.
User-specified parameters will override the canvas defaults.
save_ggplot(
plot,
file,
device = NULL,
scale = NULL,
width = NULL,
height = NULL,
units = NULL,
dpi = NULL,
limitsize = TRUE,
bg = NULL,
create.dir = FALSE,
...
)
plot |
The ggplot object to save. |
file |
File to save the plot to. |
device |
Device to use. Can either be a device function
(e.g. png), or one of "eps", "ps", "tex" (pictex),
"pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only). If
|
scale |
Multiplicative scaling factor. |
width , height |
Plot size in units expressed by the |
units |
One of the following units in which the |
dpi |
Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types. |
limitsize |
When |
bg |
Background colour. If |
create.dir |
Whether to create new directories if a non-existing
directory is specified in the |
... |
Other arguments passed on to the graphics device function,
as specified by |
The function is called for its side effects: it saves the plot to a file and returns the file path invisibly.
library(ggplot2)
p <-
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
ggtitle("My awesome plot") +
canvas(8, 6)
temp_file <- tempfile(fileext = ".png")
save_ggplot(p, temp_file)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.