Saves the plot to a temporary file with ggplot2::ggsave()
and opens it, so you see it at the size, aspect ratio and resolution of
the saved image (and faster than RStudio's plot pane draws plots full of
images). In RStudio the file opens in the Viewer pane (this needs
'rstudioapi'), elsewhere in your browser. It opens only in an
interactive session. The counterpart of nflplotR's and cfbplotR's
ggpreview().
Arguments
- plot
Plot to save, defaults to last plot displayed.
- width, height
Plot size in units expressed by the
unitsargument. If not supplied, uses the size of the current graphics device.- asp
The aspect ratio,
width / height. When a number, theheightis set towidth / asp; with nowidth, thewidthisheight * asp, or 7 inches when neither is given.- dpi
Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Only applies when converting pixel units, as is typical for raster output types.
- 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
NULL(default), the device is guessed based on thefilenameextension.- units
One of the following units in which the
widthandheightarguments are expressed:"in","cm","mm"or"px".- scale
Multiplicative scaling factor.
- limitsize
When
TRUE(the default),ggsave()will not save images larger than 50x50 inches, to prevent the common error of specifying dimensions in pixels.- bg
Background colour. If
NULL, uses theplot.backgroundfill value from the plot theme.- ...
Other arguments passed on to the graphics device function, as specified by
device.
Examples
# \donttest{
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) +
geom_point()
# opens only in an interactive session
path <- sdv_ggpreview(p, width = 5, asp = 16 / 9, dpi = 72)
file.exists(path)
#> [1] TRUE
# }
