Skip to content

Feature request: plotting the NA info in the legend when using scales with na.value= #4567

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

Open
courtiol opened this issue Jul 29, 2021 · 2 comments · May be fixed by #6023
Open

Feature request: plotting the NA info in the legend when using scales with na.value= #4567

courtiol opened this issue Jul 29, 2021 · 2 comments · May be fixed by #6023
Labels
feature a feature request or enhancement guides 📏

Comments

@courtiol
Copy link

Many scales offer the possibility to flag NAs with a particular colour on the plot but not in the legend.
For example, here in a map we flag missing values in orange but the orange is not shown in the guide at the right of the plot:

library(tidyverse)
library(rnaturalearth)
world_sf <- ne_countries(scale = "medium", returnclass = "sf")

ggplot() +
  geom_sf(mapping = aes(fill = lastcensus), data = world_sf) +
  scale_fill_fermenter(palette = 2, na.value = "orange")

Created on 2021-07-29 by the reprex package (v2.0.0)

AFAWK there is no direct way for the user to add the missing information. Of course, one can think of various hacks to do such thing but as the argument na.value is readily available, users may expect/wish to see that handled automatically.

Ideally, one could decide to add the NA colour on top or bottom (when vertical, left/right when horizontal) of the existing scale and one could also change the label associated with NA in the legend.

[Joint post with @LiamDBailey]

@thomasp85
Copy link
Member

I agree that this is a limitation with the current guide system.

@davidhodge931
Copy link

In general with a numeric colour scale, a NA value does not show up in the legend - and ideally should if it is plotted

library(palmerpenguins)
library(tidyverse)

penguins |>
  ggplot() +
  geom_point(
    aes(x = flipper_length_mm, 
        y = body_mass_g,
        col = bill_length_mm)) +
  scale_colour_gradientn(colors = viridis::rocket(9), limits = c(40, 50))
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`).

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

@teunbrand teunbrand linked a pull request Aug 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement guides 📏
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants