Skip to contents

Saves incremental plots

Usage

reveal_save(plot_list, basename, ...)

Arguments

plot_list

A list of plots created by one of the reveal_* functions (e.g. reveal_groups(), reveal_layers(), reveal_aes()]

basename

The base file name that will be used for saving.

...

Additional arguments (e.g. width, height) to be passed to ggplot2::ggsave()

Value

The paths of the saved plots, invisibly

Examples

# Create full plot
library(ggplot2)
data("mtcars")

p <- mtcars |>
  ggplot(aes(mpg, wt,
             color = factor(vs),
             group = factor(vs))) +
  geom_point() +
  geom_smooth(method="lm",
              formula = 'y ~ x',
              linewidth=1) +
  facet_wrap(~am)
p


plot_list <- reveal_groups(p)
plot_list[[1]]

plot_list[[2]]

plot_list[[3]]


# Save plots
reveal_save(plot_list, "myplot.png", width = 8, height = 4, path = tempdir())
#> 
#> ── Saving incremental plots ──
#> 
#>  /tmp/Rtmp8djt8I/myplot_0.png
#>  /tmp/Rtmp8djt8I/myplot_1.png
#>  /tmp/Rtmp8djt8I/myplot_2_last.png

# Clean temp files
file.remove(list.files(path = tempdir(), pattern = "myplot", full.names = TRUE)) 
#> [1] TRUE TRUE TRUE