Reputation: 33
I have a dataset with several variables that looks like this:
Competitor Disturbance Group MT CVt
1 M P A 17.416667 63.39274
2 M P A 11.055556 91.32450
3 M C N 13.928571 78.11438
4 B C N 13.500000 61.20542
5 B T E 12.700000 48.11819
6 B T E 27.250000 63.44356
I've made a GLMM (mMT1) with 3 predictors (Competitor, Disturbance and Group), one response (MT) and one random factor (Species, not shown in example dataset).
After fitting and checking the model, I calculated ls means with the package emmeans:
ls_MT <- emmeans(mMT1, pairwise~Disturbance*Competitor*Group, type="response")
And performed a post-hoc test:
post_MT <- emmeans(mMT1, transform="response", component="cond",list(~Disturbance|Competitor|Group,~Competitor|Group|Disturbance,~Group|Disturbance|Competitor))
pairs(post_MT)
Finally I produced a bar chart with ggplot2, based on the ls means and se
ggplot(ls_MT, aes(x=Disturbance, fill=Competitor, y=response))+
geom_bar(stat="identity",position=position_dodge())+
facet_grid(cols=vars(Group))+labs(y = "log10(MT)")+
scale_color_manual(values=c("#2ca02c","#d62728"))+
geom_errorbar(aes(ymin=ls_MT$lower, ymax=ls_MT$upper), width=.2,
position=position_dodge(.9))+
theme_light()
Which produces a plot like this:
At this point I'm struggling with 2 things:
Is there a way to have the bar plots side by side without the faceting by group? It looks ok but I'd prefer them to be one single plot rather than 3 side by side
How can I annotate on the graph the comparisons from the post-hoc test? I've seen that several functions allow to perform separate tests (e.g. stat_compare_means
) and plot those results, but I can't find a solution for Tukey's post-hoc test. Another solution could be to add
geom_signif(map_signif_level = c(" * * * "=0.001, " * * "=0.01, "*"=0.05), comparisons = list(c("P","C"),c("P","T"),c("C","T"))
but that pools together the B and M (Competitor) values of each Disturbance (P, T, C). In this case I'd actually like to compare the B and M within each of P, T and C. Or even better, how can I specify between which bars I'd like to show the results of the post-hoc? For example I'd like to compare A-T-B with E-T-B, etc.
Upvotes: 0
Views: 1434