Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New labeller: label_lut() #461

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

teunbrand
Copy link
Contributor

This PR aims to fix #458.

Briefly, you pass a named vector and the breaks will be matched to the names, and the value will be returned as the label.

Examples rendered:

devtools::load_all("~/packages/scales/")
#> ℹ Loading scales

# Example lookup table
lut <- c(
  "4" = "four wheel drive",
  "r" = "rear wheel drive",
  "f" = "front wheel drive"
)

# Typical usage
demo_discrete(c("4", "r", "f"), labels = label_lut(lut))
#> scale_x_discrete(labels = label_lut(lut))

# By default, extra values ('w') will remain as-is
demo_discrete(c("4", "r", "f", "w"), labels = label_lut(lut))
#> scale_x_discrete(labels = label_lut(lut))

# Alternatively, you can relabel extra values
demo_discrete(
  c("4", "r", "f", "w"),
  labels = label_lut(lut, nomatch = "unknown")
)
#> scale_x_discrete(labels = label_lut(lut, nomatch = "unknown"))

Created on 2024-10-07 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: lookup table based label function
1 participant