Closed zjwinn closed 6 days ago
Hi @zjwinn, you can achieve the previous behavior by adding show.legend = TRUE
in your call to geom_segment()
. A simplified reprex:
library("ggplot2")
dat <- data.frame(
x = 1:2,
y = 1:2,
z = factor(c(1, 2), levels = c("1", "2", "3"))
)
ggplot(dat, aes(x = x, y = y, color = z)) +
geom_point(show.legend = TRUE) +
scale_color_manual(values = c("1" = "goldenrod", "2" = "coral", "3" = "sienna"), drop = FALSE)
Created on 2024-06-28 with reprex v2.1.0
You can also find more info on the change in this past issue: https://github.com/tidyverse/ggplot2/issues/5728
Explanation
Hi creators/maintainers of ggplot2,
I wrote some code a while back that functioned properly in a previous version of ggplot2, and it seems that it has broken due to update. Essentially, what I see is that the color_scale_manual is not respecting the colors of levels of a factor that do not exist in the data. E.G., it will list the colors in the legend but the corresponding color will not be shown.
Minimal Reproducible Error Code
Output Images
3.4.4 Plot Example
3.5.1 Plot Example
Let me know if you need anything else from me to resolve this issue.
Thanks, Zach