Retrieves the number of layers in a given plot
layer_count(p)# S3 method for default layer_count(p)# S3 method for ggplot layer_count(p)
# S3 method for default layer_count(p)
# S3 method for ggplot layer_count(p)
plot object
number
# NOT RUN { library(ggplot2) p <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() layer_count(p) # 1 layer_count(p + geom_smooth(method = "lm") + geom_density_2d()) # 3 # }
Run the code above in your browser using DataCamp Workspace