I am plotting boxplot with facet_wrap
in ggplot2, using free scales.
Wondering how can I specify the order of each boxplot according to the table? Or to specify the order of each boxplot in each facet?
Most of the solution I have discovered worked for non-facet graph or graph with fixed scales. And the order that I wanted is not according to alphabetical order or scales.
rfall2:
Genes rfdist Category
18S vs ITS 0.75 18S-ITS
18S vs ITS 0.916667 18S-ITS
18S vs ITS 0.666667 18S-ITS
18S vs ITS 0.666667 18S-ITS
18S vs ITS 0.75 18S-ITS
18S vs ITS 0.833333 18S-ITS
18S vs 18S-ITS 0.666667 18S-ITS
18S vs 18S-ITS 0.583333 18S-ITS
18S vs 18S-ITS 0.5 18S-ITS
18S vs 18S-ITS 0.833333 18S-ITS
18S vs 18S-ITS 0.75 18S-ITS
18S vs 18S-ITS 0.75 18S-ITS
18S vs 18S-ITS 0.416667 18S-ITS
18S vs 18S-ITS-rbcL 0.833333 18S-ITS
18S vs 18S-ITS-rbcL 0.583333 18S-ITS
18S vs 18S-ITS-rbcL 0.833333 18S-ITS
18S vs 18S-ITS-rbcL 0.75 18S-ITS
18S vs 18S-ITS-rbcL 0.583333 18S-ITS
18S vs 18S-ITS-rbcL 0.833333 18S-ITS
18S vs 18S-ITS-rbcL 0.75 18S-ITS
18S vs 18S-ITS-rbcL 0.75 18S-ITS
18S vs rbcL 0.916667 18S-rbcL
18S vs rbcL 0.916667 18S-rbcL
18S vs rbcL 0.916667 18S-rbcL
18S vs rbcL 0.916667 18S-rbcL
18S vs rbcL 0.916667 18S-rbcL
18S vs rbcL 0.916667 18S-rbcL
18S vs 18S-rbcL 0.666667 18S-rbcL
18S vs 18S-rbcL 0.833333 18S-rbcL
18S vs 18S-rbcL 0.75 18S-rbcL
18S vs 18S-rbcL 0.75 18S-rbcL
18S vs 18S-rbcL 0.75 18S-rbcL
The R script I was using:
> ggplot(rfall2, aes(x=Genes, y=rfdist)) +
+ geom_boxplot() +
+ scale_y_continuous(name ="Normalized Robinson-Foulds Distance", limits=c(0,1))+
+ scale_x_discrete(name="Gene Trees Comparison") +
+ facet_wrap(vars(Category), scales="free", ncol=1) +
+ theme_bw()
I wanted to reorder for eg. on the first category "18S-ITS":
18S vs ITS, 18S vs 18S-ITS, 18S vs 18S-ITS-rbcL, ..., which I have arranged them in my table.
Any idea?