I try to get rid of the nesting (upper) facet label. So far I can only apply changes to all facet labels together and not just the grouping ones.
library(tidyverse)
library(ggh4x)
df <- as_tibble(iris) %>%
mutate(
Nester = if_else(Species == "setosa", "Short Leaves", "Long Leaves"),
Nester = factor(Nester)
) %>%
pivot_longer(!c(Species, Nester), names_to = "Measure", values_to = "Value")
ylim <- df %>%
split(.$Nester) %>%
map(., ~ range(.$Value))
df %>%
ggplot(aes(Measure, Value)) +
geom_boxplot() +
theme(axis.text.x = element_text(angle = 90, , vjust = .5)) +
facet_nested(~ Nester + Species, scales = "free_y", independent = "y") +
facetted_pos_scales(
y = list(
Species == "versicolor" ~ scale_y_continuous(limits = ylim[[1]]),
Species == "virginica" ~ scale_y_continuous(limits = ylim[[1]], guide = "none"),
Species == "setosa" ~ scale_y_continuous(limits = ylim[[2]])
)
)

Created on 2022-08-23 with reprex v2.0.2
I manually edited the plot above to show the desired plot:

I need a method that works with nested facets, as my actual data is far bigger and more complex.
EDIT: The solution needs to use nested facets.


