1

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?

EXAMPLE IMAGE

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • 2
    Welcome to SO. Reproducible questions provide a minimal amount of data so potential contributors can answer without having to spend time mocking up some data. the output of `dput(dr_stats_all)` in a code block would help folks help you. Having said that, it's very likely post-plot grob editing is what you're going to need to do to get close to what you want. – hrbrmstr Nov 06 '18 at 12:01
  • Related: [Nested facets in ggplot2 spanning groups](https://stackoverflow.com/questions/40316169/nested-facets-in-ggplot2-spanning-groups), and 'Linked' therein. Like @hrbrmstr said: massive grob digging. – Henrik Nov 06 '18 at 12:30

1 Answers1

0

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

  • Thanks! The problem with this is, that i want to see the effects of different treatments, so nested facets would be better. I will check out Hendrik`s suggestion :) – Bob Sacamano Nov 06 '18 at 12:57