Learn R Programming

scales (version 1.4.0)

compose_label: Compose two or more label formatters together

Description

This labeller provides a general mechanism for composing two or more labellers together.

Usage

compose_label(..., call = caller_env())

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.

Arguments

...

One or more labelling functions. These will be applied to breaks consecutively. Lambda syntax is allowed.

call

A call to display in error messages.

Examples

Run this code
demo_continuous(
  c(-100, 100),
  labels = compose_label(abs, number, \(x) paste0(x, " foobar"), toupper)
)

# Same result
demo_continuous(
  c(-100, 100),
  labels = compose_label(abs, label_number(suffix = " FOOBAR"))
)

Run the code above in your browser using DataLab