Reputation: 11
In the graph below I want to remove the empty groups. Please help me if you have an idea.
df = data.frame(cultivar = c("Fontane","Fontane","Fontane","Muse"),
teeltnr = c("Laat","Laat","Vroeg","Vroeg"),
treat = c("ICM","Ref","Ref","ICM"),
obs = c(388, 390, 395, 346))
p = ggplot(df, aes(treat, obs, fill = treat)) + theme_classic() +
facet_nested(~ teeltnr + cultivar) +
geom_bar(stat="identity")
Upvotes: 1
Views: 257
Reputation: 78937
You can use scales="free"
library(ggh4x)
df = data.frame(cultivar = c("Fontane","Fontane","Fontane","Muse"),
teeltnr = c("Laat","Laat","Vroeg","Vroeg"),
treat = c("ICM","Ref","Ref","ICM"),
obs = c(388, 390, 395, 346))
p = ggplot(df, aes(treat, obs, fill = treat)) + theme_classic() +
facet_nested(~ teeltnr + cultivar, scales="free") +
geom_bar(stat="identity")
p
Upvotes: 2