get_labels: List the labels used by a plot

View source: R/labels.R

get_labelsR Documentation

List the labels used by a plot

Description

get_labels() returns a named list of labels, written as character strings, indicating which labels are used by a plot.

Usage

get_labels(p, aes = NULL)

Arguments

p

A ggplot object

aes

If aes is a character vector, returns only the labels corresponding to the included aesthetics. Defaults to NULL, which returns all labels.

Details

Note that get_labels() will return NULL if a label is explicitly set to NULL or if a requested aesthetic is not present in the plot.

Value

A named list of character strings.

See Also

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

Examples

require(ggplot2)

p <- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
  geom_point(mapping = aes(color = class)) +
  geom_smooth() +
  labs(x = "Weight", y = "MPG", color = NULL)

get_labels(p)
get_labels(p, c("x", "y"))

# The colo(u)r aesthetic can be matched with or without a u
get_labels(p, "color")
get_labels(p, "colour")

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