I would like to make this kind of plot using ggplot2, geom_boxplot:
the plot has 3 groups (Taille des cours d'eau) which are "Petit" "Moyens" and "Grands" and 3 subgroups "Pesticides" "Medicaments" "Autres MP". And the order on the X is given by the subgroups rather then the groups.
If I type the following code, where Case1 is my data.frame Type defines the subgroups and Rivers the group and newMess the y values
P<-ggplot(Case1,aes(x=River,y=newMess, fill=Type)) +geom_boxplot(position = "dodge2",outlier.shape = 1)+scale_y_continuous(trans = 'log10') + stat_boxplot(geom = 'errorbar', lenght=0.5)
ggplot2 automatically order the boxplots on the groups (as in the picture below). However, I would like to have them ordered by soubgroups. Does anyone know how I can change the default order from groups to subgroups (meaning in the case below match the type (coulors) together)?
Thank you sooo much for your answer!!
(P.S I tried to change the order in the data.frame and organize it by the Type (subgroups) however this does not solve my problem)