I have the following data and a faceted plot generated from it.
# Data generation
dataPlot <- mtcars %>% select(mpg, wt, carb) %>%
group_by(carb) %>% mutate(N = n()) %>% data.frame()
# Original Faceted plot
g1 <- ggplot(dataPlot, aes(mpg, wt)) + geom_point() +
facet_wrap(~carb) + ggtitle("Original plot")
I would like to extract the following plot from the above plot. For comparison, I am generating it from the data itself.
# Refined plot with minimum 4 points
g2 <- ggplot(dataPlot %>% filter(N > 3), aes(mpg, wt)) + geom_point() +
facet_wrap(~carb) + ggtitle("Refined plot")
# Plots together
grid.arrange(g1, g2, ncol=2)
How to extract the plot g2
from the plot g1
using only the content in g1
, instead of generating it again from data?