I am trying to build a grouped boxplot with all species from the same genus (variable 'gen') colored the same way and plotted next to each others AND with species (variable 'spe') organized by increasing medians of my variable 'du' among each genus.
As I did not yet manage to do this, I used the variable (gen_spe : genus + species) in the code of my boxplot so that R organized them by genus (due to alphabetical order). However, I think that using "gen_spe" instead of the variable "spe" prevents me to organize by increasing medians too.
I add the boxplot obtained so that you understand better. Here, there are 4 colors for the 4 genera studied and species from the same genus are in the same color. I also would like to rearrange them so that e.g. in the red color, the smaller value of the Y variable is the first one and the larger value the last one (for each color separately)
And my code:
ggplot(df, aes(gen_spe, du)) +
theme_classic(base_size = 10) +
geom_boxplot(
aes(color = gen,
color = after_scale(
colorspace::desaturate(color, .2)
)),
size = 0.75
) +
ggsci::scale_color_npg(
guide = "none"
) +
guides(
color = "legend"
)
Thank you in advance !