-
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
Retain grouping information for groups with missing values #4908
Comments
Yes, you can specify it in the library(ggplot2)
iris[iris$Species=="setosa","Petal.Length"] <- NA
ggplot(iris, aes(Petal.Length, fill = Species)) +
geom_histogram() +
scale_fill_discrete(drop = FALSE)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 50 rows containing non-finite values (`stat_bin()`). Created on 2022-07-14 by the reprex package (v2.0.1) You can also use library(ggplot2)
iris$Species <- factor(iris$Species)
iris <- iris[iris$Species != "setosa", ]
ggplot(iris, aes(Petal.Length, fill = Species)) +
geom_histogram() +
scale_fill_discrete(drop = FALSE)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. Created on 2022-07-14 by the reprex package (v2.0.1) |
Thank you @yutannihilation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am coming here through an issue I encountered in ggpairs. I have missing data for one of my groups so some panels contain information about a different number of groups. I think this is a problem inherited from ggplot2, because it removes NA values from the data.
In this example I have colors for three groups.
If I remove data for one group, the colors are chosen differently, but I would like to retain the grouping information and therefore the colors provided, without manually setting colors using scale_fill_manual(). It also throws a warning. Is there a parameter which I could set that retains the groups with missing values (e.g. drop=FALSE)?
This is the ggpairs report:
ggobi/ggally#445 (comment)
The text was updated successfully, but these errors were encountered: