compose_label: Compose two or more label formatters together

View source: R/label-compose.R

compose_labelR Documentation

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

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.

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.

Examples

demo_continuous(
  c(-100, 100),
  labels = compose_label(abs, number, ~paste0(.x, " foobar"), toupper)
)

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

r-lib/scales documentation built on Nov. 2, 2024, 9:31 a.m.