Skip to contents

Quickly save a ggplot to a file

Usage

s_ggsave(
  plot = ggplot2::last_plot(),
  filename,
  path = "wd",
  width = 7,
  height = 5,
  units = "in",
  dpi = 300,
  bg = "white"
)

Arguments

plot

A ggplot object

filename

A character string of the file name

path

A character string of the file path. By default, it is the working directory.

width, height

Plot size in units expressed by the units argument. If not supplied, uses the size of the current graphics device.

units

One of the following units in which the width and height arguments are expressed: "in", "cm", "mm" or "px".

dpi

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

bg

Background colour. If NULL, uses the plot.background fill value from the plot theme.

Examples

gg <- s_plot(mtcars, mpg, wt)
if (FALSE) {
s_ggsave(gg, "plot.png")
}

# Alternatively, you can use the pipe operator
if (FALSE) {
mtcars %>%
  s_plot(mpg, wt) %>%
  s_ggsave("plot.png")
}