uses_geom_params | R Documentation |
uses_geom_params
checks that a plot's geom layer uses a specific parameter.
uses_geom_params(p, geom, ..., params = NULL, i = NULL)
uses_geom_param(p, geom, ..., params = NULL, i = NULL)
p |
A ggplot object |
geom |
A character string found in the suffix of a ggplot2 geom function,
e.g. |
... |
< |
params |
A named list of geom or stat parameter values, e.g.
|
i |
A numerical index, e.g. |
To specify a specific geom layer, either specify using position using the i
index or
by using a combination of geom
function suffix name and i
to check the ith layer that
uses the geom.
The params
argument accepts a list that contains geom, stat, or aes
parameters. This offers flexibility in certain situations where setting a
parameter on a geom_
function is actually setting a stat parameter or
aes parameter. For example, in geom_histogram(binwidth = 500)
, the
binwidth
is a stat parameter, while in
geom_histogram(fill = "blue")
, the fill
is an aes parameter.
uses_geom_params
will take this into account and check geom, stat, and
aes parameters.
Note that uses_geom_params()
can detect aes parameters, but not aes
mappings. Parameters are set to static values directly within a layer (e.g.
geom_point(color = "blue")
), while mappings associate variables in the data with plot aesthetics using
aes()
(e.g. geom_point(aes(color = class))
).
A named logical vector of the same length as the number of inputs
to ...
.
Other functions for checking geom parameters:
get_default_params()
require(ggplot2)
p <- ggplot(data = diamonds, aes(x = cut, y = price)) +
geom_boxplot(varwidth = TRUE, outlier.alpha = 0.01, fill = "blue")
uses_geom_params(
p, "boxplot", list(varwidth = TRUE, outlier.alpha = 0.01, fill = "blue")
)
uses_geom_params(
p, "boxplot", varwidth = TRUE, outlier.alpha = 0.01, fill = "blue"
)
# Unnamed arguments check that a parameter is set to any value
uses_geom_params(p, "boxplot", "fill")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.