3

I have a 2x2 study design (i.e. 4 groups) to test the interaction of two different interventions, and obtain multiple measurements for each subject, measured across different sites. I can nicely plot these data using a facet_grid for the different sites and each of the measures, showing each of the four treatment combinations. An example of this...

site <- rep(c(1:3), times = 16)
  treatmentX <- rep(c("x", "x", "y", "y"), times=12)
  treatmentY <- rep(c("a", "b", "a", "b"), times=12)
  reading1 <- runif(48)
  reading2 <- runif(48)
  reading3 <- runif(48)
  
  d <- data.frame(site, treatmentX, treatmentY, reading1, reading2, reading3)

d1 <- gather(d, reading.type, measure, reading1:reading3)
head(d1)

ggplot(d1, aes(x=treatmentX, y=measure)) +
  geom_boxplot(aes(color = as.factor(treatmentY)), 
               position = position_dodge2(preserve = 'single')) +
  facet_grid(reading.type~site, scales = "free")

enter image description here

What I would like to do is now annotate this facet_grid with the results of a 2-way ANOVA and post-hoc tests for comparisons of interest. I could run a separate 2-way ANOVA for the treatmentX:treatmentY interactions and posthoc test and use this to annotate an individual graph using ggpubr::stat_pvalue_manual(), but I'm not sure how to annotate in the context of a facet_grid, let alone automate this for each panel.

My question is whether it is possible to automatically perform this 2-way ANOVA and post-hoc analysis for each of the reading.type and site combinations and then label/paste these results onto each of the panels in a facet_grid, in order to indicate significance from a post-hoc test between groups?

Any help would be greatly appreciated!

Thanks!

phalteman
  • 3,442
  • 1
  • 29
  • 46
Timmo83
  • 119
  • 5
  • Maybe this helps: https://www.datanovia.com/en/blog/ggpubr-how-to-add-adjusted-p-values-to-a-multi-panel-ggplot/ – stefan Feb 18 '22 at 07:46

0 Answers0