get_geom_layer | R Documentation |
get_geom_layer
returns a geom layer from a plot along with the global data sets
and aesthetic mappings that the layer may inherit from.
get_geom_layer(p, geom = NULL, i = NULL)
p |
A ggplot object |
geom |
A character string found in the suffix of a ggplot2 geom function,
e.g. |
i |
A numerical index, e.g. |
Users can specify a layer in one of 3 ways:
By order of appearance with i
. The first layer to appear in the
plot (the one drawn first, on the bottom) corresponds to i = 1
.
By type of geom with geom
. get_geom_layer
will return the
first layer that uses the geom.
By a combination of geom
and
i
. get_geom_layer
will return the ith layer that uses the geom.
An object with class layer_to_check
to be manipulated further
with ggcheck functions.
require(ggplot2)
p <- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
geom_point(color = "red") +
geom_point(mapping = aes(color = class)) +
geom_smooth(se = FALSE)
get_geom_layer(p, i = 1)
get_geom_layer(p, geom = "smooth")
get_geom_layer(p, geom = "point", i = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.