ith_data_is
checks whether the student uses the supplied data set for
the ith layer of their plot.
Arguments
- p
A ggplot object or a layer extracted from a ggplot object with
get_geom_layer
.- data
A data frame
- i
A numerical index that corresponds to the first layer of a plot (1), the second layer (2), and so on.
- local_only
TRUE
orFALSE
. See the details.
Details
Functions that use the ith_
prefix are designed to eliminate the need
to call get_geom_layer
to check a specific layer in a plot, e.g. p
%>% get_geom_layer(geom = "point") %>% uses_data(mpg)
.
If local_only = TRUE
, ith_data_is
will check only the data set,
if any, that was defined locally in the function that created the ith layer.
If local_only = FALSE
, ith_data_is
will check the data used by
the ith layer, whether or not that data was defined globally in
ggplot
or locally.
Examples
require(ggplot2)
d2 <- head(mpg)
p <- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
geom_point(data = d2, color = "red") +
geom_point()
ith_data_is(p, data = head(mpg), i = 1)
#> [1] TRUE