Skip to content

Wrong mapping provided to limits that include NA #5756

@teunbrand

Description

@teunbrand

Briefly, when including NA in the limits, I interpret that as wanting to display the na.value for it.
This is fine (aside from #5749 (comment)).

library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy, colour = factor(cyl))) +
  geom_point()

p + scale_colour_discrete(limits = c("4", "5", "6", NA))

However when you don't have NA as the last limit, anything after it gets the wrong mapping.
The cyl == 8 data become grey instead of blue.

p + scale_colour_discrete(limits = c("4", "5", NA, "8"))

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorscales 🐍

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions