get_data | R Documentation |
get_data
returns the data set used by a ggplot object or a single
layer extracted from the object with get_geom_layer
.
get_data(p, local_only = FALSE)
p |
A ggplot object or a layer extracted from a ggplot object with
|
local_only |
|
When passed a ggplot object (i.e. a plot), get_data
will return only
the data that has been set globally with ggplot
.
When passed a single layer from a plot, the behavior of get_data
will
depend on the local_only
argument passed to ...
. If
local_only = TRUE
, get_data
will return only the data set, if
any, that was defined locally in the function that created the layer. If
local_only = FALSE
, get_data
will return the data used by the
layer, whether or not that data was defined globally in
ggplot
or locally.
A data frame. If no data set is found, get_data
returns
NULL
Other functions for checking data:
ith_data_is()
,
ith_data()
,
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()
get_data(p)
get_data(get_geom_layer(p, i = 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.