ith_data | R Documentation |
ith_data
returns the data set used by the ith layer.
ith_data(p, i, local_only = FALSE)
p |
A ggplot object or a layer extracted from a ggplot object with
|
i |
A numerical index that corresponds to the first layer of a plot (1), the second layer (2), and so on. |
local_only |
|
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()
.
A data frame. If no data set is found, ith_data
returns NULL
.
Other functions for checking data:
get_data()
,
ith_data_is()
,
uses_data()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.