ith_data: Which data set does the ith layer use?

View source: R/data.R

ith_dataR Documentation

Which data set does the ith layer use?

Description

ith_data returns the data set used by the ith layer.

Usage

ith_data(p, i, local_only = FALSE)

Arguments

p

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

i

A numerical index that corresponds to the first layer of a plot (1), the second layer (2), and so on.

local_only

TRUE or FALSE. See the details.

Details

If local_only = TRUE, ith_data returns the data set, if any, that was defined locally in the function that created the ith layer. If local_only = FALSE, ith_data returns the data used by the ith layer, whether or not that data was defined globally in ggplot or locally.

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") %>% get_data().

Value

A data frame. If no data set is found, ith_data returns NULL.

See Also

Other functions for checking data: get_data(), ith_data_is(), uses_data()

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(p, i = 1)

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