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.

Example

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")

A trivial boxplot example

Give group pairs you want to compare in pairs.

Boxplot with facets

Annotate your plot