# NOT RUN {
library(ggplot2)
p <- ggplot(mpg, aes(factor(year), (cty + hwy) / 2)) +
geom_boxplot() +
facet_grid(. ~ class)
mapped_vars(p) # those in use
mapped_vars(p, invert = TRUE) # those not used
p.dp <- drop_vars(p) # we drop unused vars
# number of columns in the data member
ncol(p$data)
ncol(p.dp$data)
# which vars are in the data member
data_vars(p)
data_vars(p.dp)
# which variables in data are used in the plot
mapped_vars(p)
mapped_vars(p.dp)
# the plots identical
p
p.dp
# structure and size of p
str(p, max.level = 0)
str(p.dp, max.level = 0) # smaller in size
# structure and size of p["data"]
str(p, components = "data")
str(p.dp, components = "data") # smaller in size
# }
Run the code above in your browser using DataLab