Skip to content

uses_mappings checks whether the student used one or more mappings in their plot. By default, uses_mappings ignores whether or not the student also supplied additional mappings. Use uses_extra_mappings to check if they did. If exact is TRUE, then all of the mappings have to match exactly.

Usage

uses_mappings(p, mappings, local_only = FALSE, exact = FALSE)

Arguments

p

A ggplot object or a layer extracted from a ggplot object with get_geom_layer or get_stat_layer.

mappings

One or more aesthetic mappings created with aes.

local_only

If TRUE, uses_mappings will check only the mappings defined locally in a layer for the presence of mappings. If FALSE, uses_mappings will check for mappings in the combination of global and local methods that will be used to plot a layer.

exact

If TRUE, mappings need to be mapped exactly

Value

A logical value.

See also

Other functions for checking mappings: get_mappings(), identical_aes(), ith_mappings_use(), ith_mappings()

Examples

require(ggplot2)
p <- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
  geom_point(mapping = aes(color = class))
uses_mappings(p, aes(x = displ))
#> [1] TRUE
uses_mappings(get_geom_layer(p, i = 1), aes(x = displ, color = class), local_only = FALSE)
#> [1] TRUE
uses_mappings(get_geom_layer(p, i = 1), aes(x = displ, color = class), local_only = TRUE)
#> [1] FALSE
uses_mappings(p, aes(x = displ, y = hwy), exact = TRUE)
#> [1] FALSE