-
Notifications
You must be signed in to change notification settings - Fork 2k
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
drop = FALSE
does not maintain unused factors
#5996
Comments
This is a duplicate of #5728. The solution is to add
library(dplyr, warn.conflicts = FALSE)
library(ggplot2)
mtcars_tbl <- mtcars %>%
as_tibble() %>%
mutate(
cyl = factor(cyl,
levels = c("4", "6", "8", "10"))
)
mtcars_tbl %>%
ggplot(aes(mpg, wt)) +
geom_point(aes(colour = cyl), show.legend = TRUE) +
scale_color_brewer(drop = FALSE, palette = "Dark2") Created on 2024-07-12 with reprex v2.1.1 |
This problem is associated with the
scale_fill_
andscale_color
functions, including theirmanual
versions, which contain thedrop
argument. What is happening is that if you have data where any of the factors are not in use, and you are usingdrop = FALSE
, these factors appear in the legend, but without any associated color.Created on 2024-07-11 with reprex v2.1.1
I understand that the operation of associated with
drop = FALSE
has had continuous changes over time (#4511 , #4619 , #4723 , #5214), so I have tried different iterations on the above issues, but none of them work.Created on 2024-07-11 with reprex v2.1.1
The only way to get what I am looking for is to add an empty row where the missing factors are mentioned, and plot waiting for them to be eliminated.
Created on 2024-07-11 with reprex v2.1.1
However, I think it is not an ideal solution, since
add_case()
orbind_rows()
may have limitations when you have tibbles with list or different data type.Created on 2024-07-11 with reprex v2.1.1
The text was updated successfully, but these errors were encountered: