get_labels()
returns a named list of labels,
written as character strings, indicating which labels are used by a plot.
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.
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)
#> $x
#> [1] "Weight"
#>
#> $y
#> [1] "MPG"
#>
#> $colour
#> NULL
#>
get_labels(p, c("x", "y"))
#> $x
#> [1] "Weight"
#>
#> $y
#> [1] "MPG"
#>
# The colo(u)r aesthetic can be matched with or without a u
get_labels(p, "color")
#> $color
#> NULL
#>
get_labels(p, "colour")
#> $colour
#> NULL
#>