tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.4k stars 2k forks source link

`guide_coloursteps(show.limits = T)` produces strange lower limit #5870

Closed davidhodge931 closed 1 month ago

davidhodge931 commented 2 months ago
library(tidyverse)

ggplot(mpg, aes(displ, hwy, colour = hwy)) +
  geom_point() +
  guides(colour = guide_coloursteps(show.limits = T))

Created on 2024-04-29 with reprex v2.1.0

teunbrand commented 2 months ago

The reason for this is that 10 is an out-of-bounds break that for some reason doesn't get censored. The scale then assigns a colour for 11 (because (10 + 12) / 2 = 11), which is under the lower limit of 12, so it gets na.value. Out-of-bounds breaks should probably be removed.