Hey all,
R beginner, no solution found by own research.
My code for box plots gives me the right colors, tick labels, and key legend, but not in the right order. The control should be the first one at the left, followed by coccidia, S.T, coccidia + S.T.:
disprt <- vegan::betadisper(clr_dist_matrix, phyloseq::sample_data(ps_clr)$treatment)
disprt
dis <- data.frame(group=disprt$group, distances=disprt$distances)
disg <- ggplot(dis, aes(x=group, y=distances, fill=group)) + geom_boxplot() +
xlab("") +
ylab("Distance to centroid") +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))
disg +
labs(fill="Treatment")
I can use the variable group to plot it the right way (1= control, 2= coccidia, 3= S.T., 4= both), but now the colors, tick labels and the key legend is off:
disprt
dis <- data.frame(group=disprt$group, distances=disprt$distances)
disg <- ggplot(dis, aes(x=group, y=distances, fill=group)) + geom_boxplot() +
xlab("") +
ylab("Distance to centroid") +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))
disg +
labs(fill="Treatment")
My attempt to reorder the plots was a complete fail:
disprt <- vegan::betadisper(clr_dist_matrix, phyloseq::sample_data(ps_clr)$treatment)
disprt
disprt$group <- factor(disprt$group , levels=c("Control", "Coccidia", "S. Typhimurium", "Coccidia and S. Typhimurium"))
dis <- data.frame(group=disprt$group, distances=disprt$distances)
disg <- ggplot(dis, aes(x=group, y=distances, fill=group)) + geom_boxplot() +
xlab("") +
ylab("Distance to centroid") +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))
disg +
labs(fill="Treatment")
Could you please help me to bring my box plots in the right order with the right colors and tick labels?