Closed eliocamp closed 11 months ago
I'm doing this on purpose in nested facets, which is described in the details of ?facet_nested()
:
Unlike facet_grid(), this function only automatically expands missing variables when they have no variables in that direction, to allow for unnested variables. It still requires at least one layer to have all faceting variables.
The reason why this might be desirable is explained here.
To have the default facet_grid()
behaviour, you can use the following:
library(ggplot2)
library(ggh4x)
base <- ggplot(mapping = aes(mpg, disp)) +
geom_point(data = subset(mtcars, cyl != 4)) +
geom_point(data = subset(mtcars, cyl == 4) |>
transform(cyl = NULL),
color = "gray")
base +
facet_grid2(am ~ cyl + vs, strip = strip_nested())
Created on 2023-07-19 with reprex v2.0.2
I'm going to close this because this is by design and viable workarounds are available.
Trying to solve other issues I found that
facet_nested()
behaves strangely in specific case.I'm trying to plot data belonging to a category as "reference" data in every panel and without getting a panel of its own. This seems to work:
Which is similar to ggplot2
s
facet_grid()`.But if I add a nested facet, the "reference" data is moved to its own panel:
And note that this is not what ggplot2 does in this case
(Although note that ggplot2 does draw phantom panels if one uses a global data (see: https://github.com/tidyverse/ggplot2/issues/5356) although it draws the value of the facet, which ggh4x doesn't do.)
Created on 2023-07-19 with reprex v2.0.2