The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Package {ggsnap}


Title: Save a 'ggplot2' Plot using '+' Operator
Version: 0.1.2
Description: Provides ggsnap(), which saves a 'ggplot2' plot to disk in a '+' chain, acting as a thin, chainable wrapper around ggplot2::ggsave(). Can be called multiple times in a chain to save different snapshots.
License: MIT + file LICENSE
Imports: ggplot2
Suggests: testthat (≥ 3.0.0), png, rlang, glue, spelling
Config/testthat/edition: 3
Encoding: UTF-8
Config/roxygen2/version: 8.0.0
Language: en-US
NeedsCompilation: no
Packaged: 2026-07-07 17:55:06 UTC; Or.Gadish
Author: Or Gadish [aut, cre, cph]
Maintainer: Or Gadish <orgadish@gmail.com>
Repository: CRAN
Date/Publication: 2026-07-16 13:10:02 UTC

ggsnap: Save a 'ggplot2' Plot using '+' Operator

Description

Provides ggsnap(), which saves a 'ggplot2' plot to disk in a '+' chain, acting as a thin, chainable wrapper around ggplot2::ggsave(). Can be called multiple times in a chain to save different snapshots.

Author(s)

Maintainer: Or Gadish orgadish@gmail.com [copyright holder]

Authors:


Save a ggplot2 plot using the + operator

Description

ggsnap() saves a ggplot2 plot to disk inside a + chain, rather than requiring a separate ggplot2::ggsave() call. It accepts the same arguments as ggplot2::ggsave().

The plot is returned invisibly so the chain can continue — meaning ggsnap() can be used multiple times in a single chain to capture intermediate states.

ggsave_snap() is an alias provided for discoverability.

Usage

ggsnap(
  filename,
  width = NA,
  height = NA,
  units = c("in", "cm", "mm", "px"),
  dpi = 300,
  ...
)

ggsave_snap(
  filename,
  width = NA,
  height = NA,
  units = c("in", "cm", "mm", "px"),
  dpi = 300,
  ...
)

Arguments

filename

File name to create on disk.

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). Only applies when converting pixel units, as is typical for raster output types.

...

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

scale

Multiplicative scaling factor.

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.

create.dir

Whether to create new directories if a non-existing directory is specified in the filename or path (TRUE) or return an error (FALSE, default). If FALSE and run in an interactive session, a prompt will appear asking to create a new directory when necessary.

Value

The ggplot object, invisibly.

Examples

library(ggplot2)

save_dir <- tempdir()

# Single use
ggplot(mtcars) +
  aes(mpg, wt) +
  geom_point() +
  labs(title = "Cars") +
  ggsnap(file.path(save_dir, "cars.png"), width = 6, height = 4)

# Two snapshots capturing before and after changing the theme
ggplot(mtcars) +
  aes(mpg, wt) +
  geom_point() +
  labs(title = "Cars") +
  ggsnap(file.path(save_dir, "base.png")) +
  theme_minimal() +
  ggsnap(file.path(save_dir, "minimal.png"))

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.