Here I managed to sort the box-plots in the right order.
However, it is not obvious to me, where I shall change the colors.
scale_colour_manual(Treatment=c("#00BFC4", "#F8766D", "#7CAE00", "#C77CFF")) + didn't work and scale_fill_manual is not supported with gather.
adiv16 <- data.frame(
"Observed" = phyloseq::estimate_richness(gps16, measures = "Observed"),
"Shannon" = phyloseq::estimate_richness(gps16, measures = "Shannon"),
"PD" = picante::pd(samp = data.frame(t(data.frame(phyloseq::otu_table(gps16)))), tree = phyloseq::phy_tree(gps16)) [ ,1],
"Treatment" = phyloseq::sample_data(gps16)$treatment)
adiv_plot16 <- adiv16 %>%
mutate(Treatment = forcats::fct_relevel(Treatment, "Control", "Coccidia", "S. Typhimurium")) %>%
gather(key = metric, value = value, c("Observed", "Shannon", "PD")) %>%
mutate(metric = factor(metric, levels = c("Observed", "Shannon", "PD"))) %>%
ggplot(aes(group=Treatment, x = Treatment, y = value)) +
geom_boxplot(outlier.color = NA) +
geom_jitter(aes(color = Treatment), height = 0, width = .2) +
labs(x = "", y = "") +
facet_wrap(~ metric, scales = "free") +
theme(legend.position="bottom") +
theme(axis.text.x = element_blank(), axis.ticks.x=element_blank())
adiv_plot16
