reveal_panels {ggreveal} | R Documentation |
Reveal plot by panel
Description
Turns a ggplot into a list of plots, showing data incrementally by panels.
Usage
reveal_panels(p, order = NULL, what = c("data", "everything"))
Arguments
p |
A ggplot2 object |
order |
(optional) A numeric vector specifying in which order to reveal the panels For example, if there are three panels in the plot, Any panel not included in the vector will be omitted from the incremental
plots. E.g.: with By default, the first plot is blank, showing layout elements (title,
legends, axes, etc) but no data. To omit the blank plot, include |
what |
(optional) one of |
Value
A list of ggplot2 objects, which can be passed to reveal_save()
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
# Only data
plot_list <- reveal_panels(p, what = "data")
plot_list[[1]]
plot_list[[2]]
plot_list[[3]]
# Everything
plot_list <- reveal_panels(p, what = "everything")
plot_list[[1]]
plot_list[[2]]
plot_list[[3]]
# Save plots
reveal_save(plot_list, "myplot.png", width = 8, height = 4, path = tempdir())
# Clean temp files
file.remove(list.files(path = tempdir(), pattern = "myplot", full.names = TRUE))