-
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
Facets use nonexistent values if removed from inside geoms. #5356
Comments
I've noticed this too but have no idea whether this behaviour is intended or not. |
If it's any help to decide, not adding global data and just passing the correct data to the geoms works as expected: library(ggplot2)
ggplot(mapping = aes(mpg, disp)) +
geom_point(data = subset(mtcars, cyl != 4)) +
geom_point(data = subset(mtcars, cyl == 4) |>
transform(cyl = NULL),
color = "gray") +
facet_wrap(~cyl, drop = TRUE) Created on 2023-07-19 with reprex v2.0.2 |
facet_wrap()
(andfacet_grid()
) seem to draw panels for values that are not drawn if they are removed using thedata
argument in a geom.So, this draws a panel for cyl = 4 even though that data doesn't exist in the plot.
Compare with the result removing the category at the top-level call of the plot.
The use case for this is to use one of the categories as the reference and draw it in every panel, but I don't want it to have its own panel. So my though was to plot one geom without the reference category and then another with just the reference and without the faceting variable. But it doesn't work because it adds the panel for the reference category even though that category is never seen by any geom.
Created on 2023-07-19 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: