box plots are overlapping in ggplot2

I am trying to plot several variable in one boxplot for my paper but the box plots are overlapping and I couldn't find any solution for this problem.
here is my code:
<- ggplot (MetaNotOne.art1)+

<-geom_boxplot(aes(x=TISSUE,y=simpson.art1), width=0.5, position = "dodge") +

<- geom_boxplot(aes(x=TISSUE,y=shannon), width=0.5, position = "dodge")+

<- facet_wrap(~SOIL)+

<- xlab("Organ type")+ylab("Diversity")+ scale_x_discrete(labels = c("Twig", "Leaf","Root"))

but it doesn't work and box plots of different variables are plotted on top of each other.
I read all the relevant pages in stack overflow and other websites, but nothing worked.
I also tried adding another layer of boxplot using another data frame which did not work...
could anyone please help me with this?

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

1 Like

I think it's because you call geom_boxplot twice, so you generate 2 boxplots on top of each other, position dodge doesn't work, because they don't know each other.
Try to convert to long format, put both value columns (simpson.art1, shannon) into one (do you know how to use gather?) then it may work.

1 Like

Thank you Matthias. I used your method and it worked.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.