get_mappings
returns the mappings used by a ggplot object or a single
layer extracted from the object with get_geom_layer
or get_stat_layer
.
Arguments
- p
A ggplot object or a layer extracted from a ggplot object with
get_geom_layer
orget_stat_layer
.- local_only
TRUE
orFALSE
. Shouldget_mappings
return only the mappings defined locally in a layer. This has no effect whenp
is a ggplot object.
Value
A list with class uneval, as returned by aes
Components of the list are either quosures or constants.
Details
When passed a ggplot object (i.e. a plot), get_mappings
will return
only the mappings that have been set globally with
ggplot
. When passed a single layer from a plot, the
behavior of get_mappings
will depend on the value of
local_only
. If local_only = TRUE
, get_mappings
will
return only the mappings defined locally in a layer. When local_only =
FALSE
, get_mappings
will return the combination of global and local
methods that will be used to plot a layer.
See also
Other functions for checking mappings:
identical_aes()
,
ith_mappings_use()
,
ith_mappings()
,
uses_mappings()
Examples
require(ggplot2)
p <- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
geom_point(mapping = aes(color = class))
get_mappings(p)
#> Aesthetic mapping:
#> * `x` -> `displ`
#> * `y` -> `hwy`
get_mappings(get_geom_layer(p, i = 1), local_only = FALSE)
#> Aesthetic mapping:
#> * `x` -> `displ`
#> * `y` -> `hwy`
#> * `colour` -> `class`