uses_labels | R Documentation |
uses_labels()
tests whether a plot uses one or more labels.
uses_labels(p, ...)
p |
A ggplot object |
... |
< |
Note that uses_labels()
will match NULL
if a label is explicitly set to
NULL
or if a requested aesthetic is not present in the plot.
A named logical vector of the same length as the number of inputs
to ...
.
Other functions for checking labels:
get_default_labels()
,
get_labels()
require(ggplot2)
p <- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
geom_point(mapping = aes(color = class, shape = drv)) +
geom_smooth() +
labs(title = "My plot", x = "Weight", y = "MPG", color = NULL)
# Unnamed arguments check if a label is set for the given aesthetic
uses_labels(p, "title", "subtitle", "x", "y")
# The check will return TRUE for labels set to NULL
uses_labels(p, "color")
# The check will return TRUE for aesthetics with default labels
uses_labels(p, "shape")
# Named arguments check if the label matches an expected value
uses_labels(p, x = "Weight")
uses_labels(p, x = "Weight", y = "MPG", color = NULL)
# You can check for default labels with default_label()
uses_labels(p, shape = default_label(), x = default_label())
# The colo(u)r aesthetic can be matched with or without a u
uses_labels(p, color = NULL)
uses_labels(p, colour = NULL)
# Inputs can be passed from a list, with or without the !!! operator
label_list <- list(x = "Weight", y = "MPG", color = NULL)
uses_labels(p, label_list)
uses_labels(p, !!!label_list)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.