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

Show NA keys better #5759

Merged
merged 4 commits into from
Mar 18, 2024
Merged

Show NA keys better #5759

merged 4 commits into from
Mar 18, 2024

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5749.

Briefly, when including NA as part of discrete layers, the legend checks for NA values in the data. What the legend didn't consider, is that the values might not be NA themselves but map to NA for some reason. This PR tries to detect such cases by checking if any values in the data are not included in the breaks.

Reprex from #5749 (comment)

library(palmerpenguins)
devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

penguins |>
  ggplot() +
  geom_point(
    aes(x = flipper_length_mm, 
        y = body_mass_g,
        col = species)) +
  scale_colour_manual(
    values = c("red", "blue"), 
    limits = c("Adelie", "Gentoo", NA)
  )
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`).

Created on 2024-03-07 with reprex v2.1.0

@teunbrand teunbrand added this to the ggplot2 3.5.1 milestone Mar 7, 2024
Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit dfec855 into tidyverse:main Mar 18, 2024
12 checks passed
@teunbrand teunbrand deleted the show_na_keys branch March 18, 2024 09:19
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.

NA key does not show up in legend when colour limits include NA
2 participants