This is a wrapper around ggplot2::ggsave() with some ATLAS-specific defaults. The aspect ratio is fixed to 0.618 (the golden ratio) unless the height is manually defined. Plots are automatically spell checked and warnings are returned if there are possible mistakes. Finally, plots saved as a pdf have the fonts embedded using extrafont::embed_fonts().

ggsave2(
  plot = ggplot2::last_plot(),
  filename,
  device = NULL,
  path = NULL,
  width = 7,
  height = NULL,
  units = "in",
  dir = c("h", "v"),
  dpi = "retina",
  embed_fonts = FALSE,
  ...
)

Arguments

plot

Plot to save, defaults to last plot displayed.

filename

File name to create on disk.

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 the filename extension.

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.

width

Plot size in units ("in", "cm", or "mm").

height

Plot size in units ("in", "cm", or "mm"). If not supplied, uses 0.618 * width when dir = "h" and 1.618 * width when dir = "v".

units

Units of plot size ("in", "cm", or "mm"). Default is inches.

dir

Orientation of the plot. One of h (default) for horizontal or v for vertical.

dpi

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

embed_fonts

Logical. Use Ghostscript to embed fonts in a PDF graphic?

...

Additional arguments passed to ggplot2::ggsave()

Value

None. Called for side effects.

Examples

# \donttest{
library(ggplot2)
p <- ggplot(mtcars, aes(mpg, wt)) +
 geom_point()

ggsave2(p, "/mtcars.pdf", path = tempdir())
ggsave2(p, "/mtcars.png", path = tempdir())
# }