| Title: | 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. |
| Authors: | Or Gadish [aut, cre, cph] |
| Maintainer: | Or Gadish <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-07-17 07:52:50 UTC |
| Source: | https://github.com/orgadish/ggsnap |
+ operatorggsnap() 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.
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, ... )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, ... )
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
|
The ggplot object, invisibly.
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"))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"))