Skip to contents

Single line wrapper to save plot as png

Usage

save_plot(
  p,
  filename,
  width = 2400,
  height,
  units = c("px", "cm", "mm"),
  res = 300
)

Arguments

p

A plot object

filename

character to save plot

width

In units

height

In units. If missing, height will be scaled to width at the golden ratio.

units

Units of width and height. "px" — pixels, the default, "cm", or "mm". "in" are not allowed on principle.

res

resolution, default 300px

Value

nothing. Writes a plot to filename

Examples

if (FALSE) { # \dontrun{

lovely_plot <- plot(1:10)
# why use three lines
png("lovely_plot.png")
lovely_plot
dev.off()

#when you could use one
save_plot(p = lovely_plot, "lovely_plot.png")

} # }