-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
NA key does not show up in legend when colour limits include NA #5749
Comments
This is to be expected. For discrete scales, limits determine the 'universe' of values and if it doesn't include A bug is that NA isn't shown as a key even if included as limits: library(palmerpenguins)
library(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 |
Ah, okay it seems sort of inconsistent to me then, as if you set the limits to be only Adelie and Gentoo, it still plots NA |
Sorry 'shouldn't be shown' should have been 'shouldn't be shown in the legend'. Apologies for the confusion |
Oh okay. As a general rule, I think anything that is plotted should be in the legend. That last plot is weird the way there is no grey dot in the legend library(palmerpenguins)
library(tidyverse)
p <- penguins |>
ggplot() +
geom_point(
aes(x = flipper_length_mm,
y = body_mass_g,
col = sex))
#I think there should be a legend NA value here if NA is plotted
p +
scale_colour_manual(values = c("red", "blue"), limits = c("female", "male"))
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`). #The NA is missing a grey dot in the legend
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 |
Well that is the default behaviour for scales that display a legend, but users can intervene by setting the |
Is the oob default for |
Neither: there are no bounds to be out of, unlike continuous scales. For discrete scales, the default is to honour the |
Feel free to close, if you think everything is fine here |
I think the NA-key not showing up when including NA in the limits is a bug, so let's keep this open for now. |
Created on 2024-03-06 with reprex v2.1.0
The text was updated successfully, but these errors were encountered: