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

Improve behaviour when labeller() does not find a match in lookup table #4599

Closed
stragu opened this issue Aug 31, 2021 · 1 comment
Closed
Labels
facets 💎 help wanted ❤️ we'd love your help! messages requests for improvements to error, warning, or feedback messages

Comments

@stragu
Copy link
Contributor

stragu commented Aug 31, 2021

Currently, ggplot2::labeller() silently labels the facets with "NA" if the user supplies unnamed character vectors.

library(ggplot2)
ggplot(ToothGrowth, aes(y = len)) + 
  geom_boxplot() +
  facet_wrap(vars(supp), labeller = labeller(supp = c("orange juice yum", "vitamin C yuck")))

If there is a typo in the name (or if there just isn't a new label defined in the vector), the same thing happens: "NA" is given as a title.

library(ggplot2)
ggplot(ToothGrowth, aes(y = len)) + 
  geom_boxplot() +
  facet_wrap(vars(supp), labeller = labeller(supp = c("OJ" = "orange juice yum", "vC" = "vitamin C yuck")))

I am not sure what would be most appropriate, but I would have expected to get something like this:

Warning: labeller() could not match one or more of the original labels. The facets were titled "NA".
ℹ: did you forget to provide a named character vector, or are some labels missing from the lookup table?

The function allows using lookup tables that include superfluous data, which is probably good for flexibility, but I think that naming a facet with "NA" should throw a warning, or at least a message, when the is not enough data.

Or should the default behaviour change to using the original label if no match is found, allowing the use of partial lookup tables? I can see people wanting to only cherry pick a couple of labels to replace.

Using:

  • ggplot2 3.3.5
  • R 4.1.1
@thomasp85 thomasp85 added facets 💎 messages requests for improvements to error, warning, or feedback messages labels Oct 28, 2021
@hadley hadley added the help wanted ❤️ we'd love your help! label Apr 19, 2022
@teunbrand
Copy link
Collaborator

Considered fixed by #5432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
facets 💎 help wanted ❤️ we'd love your help! messages requests for improvements to error, warning, or feedback messages
Projects
None yet
Development

No branches or pull requests

4 participants