library(ggpubr) #required package dat <- my_data # Edit from here x <- which(names(dat) == "Group") # name of grouping variable y <- which( names(dat) == "INFg" # names of variables to test | names(dat) == "IL-10" | names(dat) == "IL-12p70" | names(dat) == "IL-1b" | names(dat) == "IL-2" | names(dat) == "IL-4" | names(dat) == "IL-5" | names(dat) == "IL-6" | names(dat) == "KCGRO" | names(dat) == "TNFa" ) method1 <- "anova" # one of "anova" or "kruskal.test" method2 <- "t.test" # one of "wilcox.test" or "t.test" my_comparisons <- list( c("CON-BF", "FVT-FORM" ), c("CON-BF", "SM-FORM" ), c("FVT-FORM", "SM-FORM") ) # comparisons for post-hoc tests # Edit until here # Edit at your own risk for (i in y) { for (j in x) { p <- ggboxplot(dat, x = colnames(dat[j]), y = colnames(dat[i]), color = colnames(dat[j]), legend = "none", palette = "npg", add = "jitter" ) print( p + stat_compare_means(aes(label = paste0(..method.., ", p-value = ", ..p.format.., " (", ifelse(..p.adj.. > 0.05, "not significant", ..p.signif..), ")")), method = method1, label.y = max(dat[, i], na.rm = TRUE) ) + stat_compare_means(comparisons = my_comparisons, method = method2, label = "p.format") # remove if p-value of ANOVA or Kruskal-Wallis test >= 0.05 ) } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter