label_glue {scales} | R Documentation |
Interpolated labels
Description
Use label_glue()
to perform string interpolation using the glue
package. Enclosed expressions will be evaluated as R code.
Usage
label_glue(pattern = "{x}", ..., parse = FALSE, .envir = caller_env())
Arguments
pattern |
A glue string used for formatting. The |
... |
Arguments passed on to |
parse |
Whether to return labels as expressions. |
.envir |
[ |
Value
All label_()
functions return a "labelling" function, i.e. a function that
takes a vector x
and returns a character vector of length(x)
giving a
label for each input value.
Labelling functions are designed to be used with the labels
argument of
ggplot2 scales. The examples demonstrate their use with x scales, but
they work similarly for all scales, including those that generate legends
rather than axes.
See Also
Other labels for continuous scales:
label_bytes()
,
label_currency()
,
label_number_auto()
,
label_number_si()
,
label_ordinal()
,
label_parse()
,
label_percent()
,
label_pvalue()
,
label_scientific()
Other labels for discrete scales:
label_dictionary()
,
label_parse()
,
label_wrap()
Examples
# Example variables
animal <- "penguin"
species <- c("Adelie", "Chinstrap", "Emperor", "Gentoo")
# Typical use, note that {x} will become the breaks
demo_discrete(species, labels = label_glue("The {x}\n{animal}"))
# It adapts to the breaks that are present
demo_discrete(species[-3], labels = label_glue("The {x}\n{animal}"))
# Contrary to directly glueing species + animal, which results in mislabelling!
demo_discrete(species[-3], labels = glue::glue("The {species}\n{animal}"))