ggplot2, x-axis issues with facet_grid

I'm very new to R and trying to create a grid of violin plots for my data. I was able to get the grid layout I want it, however, when I make the grid, my plots are on the x-axis where they would be if they were all plotted together.

p2 <- ggplot(data, aes(x=Treatment, y=ECM, fill=Treatment)) + 
      geom_violin(trim=FALSE) +   facet_grid (Time ~ Duff) +
      labs(title=" ",x=" ", y = "ECM Root Colonization (%)")
p2 + theme_classic() + theme(legend.position="right") + stat_summary(fun=mean, geom="point", size=2, color="black") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(),axis.ticks.x=element_blank()) + scale_fill_discrete(name = "Treatment", labels = c("B-M- B/B", "B-M- B/M (B)", "B-M- B/M (M)", "B-M- M/M", "B-M+ B/B", "B-M+ B/M (B)", "B-M+ B/M (M)", "B-M+ M/M", "B+M- B/B", "B+M- B/M (B)", "B+M- B/M (M)", "B+M- M/M", "B+M+ B/B", "B+M+ B/M (B)","B+M+ B/M (M)", "B+M+ M/M")) +
      theme(strip.background = element_rect(colour="black", fill="white", 
                                            size=1.5, linetype="solid")) +
      theme(strip.text.x = element_text(size=15, color="black",

Because the x-axis is "Treatment", which is also my fill, I tried freeing the scale with the following codes, but that didn't change the plots.

+   facet_grid (Time ~ Duff, scales="free")
+   facet_grid (Time ~ Duff, scales="free_x")

I've also tried to recreate it using facet_wrap as well, but was unsuccessful.

I'm happy to include any other information that may be helpful. Thank you in advance for any suggestions!

Read more here:

Content Attribution

This content was originally published by Mstra88 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: