p <- ggplot(mpg, aes(factor(year), (cty + hwy) / 2)) +
geom_boxplot() +
geom_point(color = "red") +
facet_grid(. ~ class) +
ggtitle("Example plot")
p
# str(p) vs. summary(p)
str(p)
summary(p) # from pacakge 'ggplot2'
# structure of p at 2 levels of nesting
str(p, max.level = 2, size = FALSE)
# top level structure and size of p
str(p, max.level = 0)
# names of ggplot object members/slots
# the class of ggplot objects changed in version >= 4.0.0
if (utils::packageVersion("ggplot2") < "4.0.0") {
names(p)
} else {
S7::S7_class(p)
}
# structure and size of p["data"]
str(p, max.level = 2, components = "data")
# structure and size of p["layers"]
str(p, max.level = 1, components = "layers")
Run the code above in your browser using DataLab