Skip to content

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

Open
@courtiol

Description

@courtiol

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions