Drop unused data from the plot to reduce the object size
Examples
library(ggplot2)
p <- ggplot(data = mtcars, aes(x = mpg, y = wt, colour = cyl)) +
geom_point()
object.size(p)
#> 13984 bytes
colnames(p$data)
#> [1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb"
p_slim <- slim_data(p)
object.size(p_slim)
#> 10912 bytes
colnames(p_slim$data)
#> [1] "mpg" "cyl" "wt"