ith_mappings_use: Does the ith layer use one or more aesthetic mappings?

View source: R/mappings.R

ith_mappings_useR Documentation

Does the ith layer use one or more aesthetic mappings?

Description

ith_mappings_use checks whether the student uses the supplied mappings in the ith layer of their plot.

Usage

ith_mappings_use(p, mappings, i, 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.

i

A numerical index that corresponds to the first layer of a plot (1), the second layer (2), and so on. ith_mappings_use will check the aesthetics used by the ith layer.

local_only

If TRUE, ith_mappings_use will check only the mappings defined locally in a layer for the presence of mappings. If FALSE, ith_mappings_use 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

Details

ith_mappings_use ignores whether or not the student supplied additional mappings as well. Functions that use the ith_ prefix are designed to eliminate the need to call get_layer to check a specific layer in a plot, e.g. p uses_mappings(aes(color = class)).

Value

A logical value

See Also

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

Examples

require(ggplot2)
p <- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
  geom_point(mapping = aes(color = class)) +
  geom_smooth()
ith_mappings_use(p, i = 1, aes(x = displ), local_only = FALSE)
ith_mappings_use(p, i = 1, aes(x = displ), local_only = TRUE)
ith_mappings_use(p, i = 2, aes(x = displ, y = hwy), local_only = FALSE)

rstudio-education/ggcheck documentation built on May 12, 2023, 11:33 a.m.