ggpval
allow you to generate statistical test and add test p-value to plots automatically. P-valules can be presented as formated p-values or with stars (e.g. *, **). Alternatively one can also annotation groups with text.
Simulate data with groups.
library(ggpval)
library(data.table)
library(ggplot2)
A <- rnorm(200, 0, 3)
B <- rnorm(200, 2, 4)
G <- rep(c("G1", "G2"), each = 100)
dt <- data.table(A, B, G)
dt <- melt(dt, id.vars = "G")
Give group pairs you want to compare in pairs
.