get_default_labels | R Documentation |
What is the default label for a plot aesthetic?
get_default_labels(p, aes = NULL)
p |
A ggplot object |
aes |
If |
A named list in which each element is a character string
or NULL
.
Strings are returned for aesthetics with a default value.
NULL
is returned for aesthetics that do not exist in the plot,
or non-aesthetic labels that do not have a default value, like title
.
Other functions for checking labels:
get_labels()
,
uses_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)
# Returns the label the ggplot would create by default for an aesthetic
get_default_labels(p, "x")
get_default_labels(p, c("x", "y"))
get_default_labels(p)
# If an aesthetic does not exist, returns NULL
get_default_labels(p, "size")
# Non-aesthetic labels have no default value, so they also return NULL
get_default_labels(p, "title")
get_default_labels(p, "comment")
# The colo(u)r aesthetic can be matched with or without a u
get_default_labels(p, "color")
get_default_labels(p, "colour")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.