get_default_labels: What is the default label for a plot aesthetic?

get_default_labelsR Documentation

What is the default label for a plot aesthetic?

Description

What is the default label for a plot aesthetic?

Usage

get_default_labels(p, aes = NULL)

Arguments

p

A ggplot object

aes

If aes is a character vector, returns only the default labels (based on the plot p) that correspond to the included aesthetics. Defaults to NULL, which returns the default values of all labels.

Value

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.

See Also

Other functions for checking labels: get_labels(), uses_labels()

Examples

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")

rstudio-education/ggcheck documentation built on May 12, 2023, 11:33 a.m.