| 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:
Or Gadish orgadish@gmail.com [copyright holder]
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 |
One of the following units in which the |
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
|
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"))