# 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())
# Clean temp files
file.remove(list.files(path = tempdir(), pattern = "myplot", full.names = TRUE))
Run the code above in your browser using DataLab