quick_save_plot: Save and preview a plot

Description Usage Arguments Value Examples

View source: R/quick_save_plot.R

Description

Convenience function to quickly save a plot to an image file and immediately inspect it. Based on the function 'ggpreview' by Tristan (TJ) Mahr.

Usage

1
2
3
4
5
6
7
8
9
quick_save_plot(
  plot = ggplot2::last_plot(),
  fname = tempfile(fileext = paste0(".", device)),
  inspect = TRUE,
  device = "png",
  dpi = 320,
  scale = 1,
  ...
)

Arguments

plot

A plot object. If unspecified, uses the most recent printed plot.

fname

A filename for the plot to be saved. Uses a temporary file in the user's temporary folder if unspecified.

inspect

A logical defaulting to 'TRUE' indicating whether to immediately open the file for inspection.

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). Defaults to 'png'.

dpi

Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types.

scale

Multiplicative scaling factor.

...

Additional arguments passed on to the 'ggsave' function.

Value

Saves a plot to a temporary file in the user's temp directory

Examples

1
2
ggplot(mtcars, aes(mpg, wt)) + geom_point()
quick_save_plot()

bschneidr/schneidr documentation built on Dec. 25, 2021, 4:55 p.m.