uses ggsave to save a ggplot object to file and then opens a new device and displays it.

ggpreview(
  plot = ggplot2::last_plot(),
  filename = tempfile(fileext = ".png"),
  ...
)

Arguments

plot

Plot to save, defaults to last plot displayed.

filename

File name to create on disk.

...

Arguments passed on to ggplot2::ggsave

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).

path

Path of the directory to save plot to: path and filename are combined to create the fully qualified file name. Defaults to the working directory.

scale

Multiplicative scaling factor.

width,height,units

Plot size in units ("in", "cm", "mm", or "px"). 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), 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 the plot.background fill value from the plot theme.

See also

Examples

if (FALSE) {
library(ggplot2)
p <- ggplot(mtcars, aes(mpg, wt)) +
    geom_point() +
    ggpreview()
}