简体   繁体   中英

ggplot2 / facet_wrap - shared labels for variables

i have a problem i can't find a solution for.

I have a data set with 3 sample sites and different sample variables ("Bulk" and "Rhizosphere").

My code:

ggplot(data=dr_stats_all, aes(x=treatment, y=co2c, fill=type)) + 
  geom_bar(stat = "identity") + 
  facet_wrap(~ site  + type, nrow=1) 

This gives me six subplots with the sample site labels twice for "Bulk" and "Rhizosphere".

Is there a way to share the lables from the sample sites?

图像示例

Would it not be easier to use only site to facet? You already use type to determine the fill, so adding a legend with the type (which is automatic) would suffice.

ggplot(data=dr_stats_all, aes(x=treatment, y=co2c, fill=type)) + 
geom_bar(stat = "identity") + 
facet_wrap(~ site, nrow=1)

If you really want to have nested facets, I also suggest taking a look at Henrik's suggestion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM