plotSave | R Documentation |
'plotSave()' is a convenient function for saving a plot. It saves the plot that the plotCMD is to make, using the size of the current graphics device by default. It also guesses the type of graphics device from the extension. This function is very convinent when saving a plot as a pdf or svg file and the letters in the plot need to be able to copied.
plotSave(
filename,
Plot = NULL,
plotCMD = NULL,
device = NULL,
path = NULL,
scale = 1,
width = NA,
height = NA,
units = c("in", "cm", "mm")[1],
dpi = 300,
limitsize = TRUE,
...
)
filename |
File name to create on disk. |
Plot |
Plot based on a return value of a plot command. The class of the return value should be able to dealed by 'plot'() function. |
plotCMD |
Plot based on this plot command, cannot use a return value of a plot command. |
device |
Device to use. Can be 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). |
path |
Path to save plot to (combined with filename). |
scale |
Multiplicative scaling factor. |
width , height , units |
Plot size in 'units' ("in", "cm", or "mm"). If not supplied, uses the size of current graphics device. |
dpi |
Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types. |
limitsize |
When 'TRUE' (the default), 'plotSave' will not save images larger than 50x50 inches, to prevent the common error of specifying dimensions in pixels. |
... |
Other arguments passed on to graphics 'device'. |
returnPlot |
When 'FALSE' (the default), plotSave will not return the value that plotCMD might return. |
Similar usage can refer to ggplot()
.
# using plotCMD parameter
plotSave("mtcars.pdf", plotCMD = plot(mtcars$mpg, mtcars$wt))
plotSave("mtcars.pdf", plotCMD = ggplot(mtcars, aes(mpg, wt)) + geom_point())
plotSave("mtcars.pdf", plotCMD = plot(mtcars$mpg, mtcars$wt),
width = 4, height = 4)
plotSave("mtcars.pdf", plotCMD = plot(mtcars$mpg, mtcars$wt),
width = 20, height = 20, units = "cm")
# using Plot parameter
g = ggplot(mtcars, aes(mpg, wt)) + geom_point()
h = hist(rnorm(100))
plotSave("mtcars.pdf", Plot = g)
plotSave("mtcars.png", Plot = h)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.