library(ggpubr) dat <- my_data # Edit from here # x <- which(names(dat) == "Species") # name of grouping variable y <- which(names(dat) == "Sepal.Length" # names of variables to test | names(dat) == "Sepal.Width" | names(dat) == "Petal.Length" | names(dat) == "Petal.Width") method <- "t.test" # one of "wilcox.test" or "t.test" paired <- FALSE # if paired make sure that in the dataframe you have first all individuals at T1, then all individuals again at T2 # Edit until here # Edit at your own risk for (i in y) { for (j in x) { ifelse(paired == TRUE, p <- ggpaired(dat, x = colnames(dat[j]), y = colnames(dat[i]), color = colnames(dat[j]), line.color = "gray", line.size = 0.4, palette = "npg", legend = "none", xlab = colnames(dat[j]), ylab = colnames(dat[i]), add = "jitter" ), p <- ggboxplot(dat, x = colnames(dat[j]), y = colnames(dat[i]), color = colnames(dat[j]), palette = "npg", legend = "none", add = "jitter" ) ) # Add p-value print(p + stat_compare_means(aes(label = paste0(..method.., ", p-value = ", ..p.format.., " (", ifelse(..p.adj.. >= 0.05, "not significant", ..p.signif..), ")")), method = method, paired = paired, # group.by = NULL, ref.group = NULL )) } }
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