I have the following data
library(tidyverse)
library(ggsignif)
set.seed(1)
a <- rnorm(n = 10, mean = 5, sd = 1)
b <- rnorm(n = 10, mean = 5.8, sd = 1)
data <- data.frame(label = c(rep("A", 10), rep("B", 10)), id = c(1:10, 1:10),
value = c(a, b))
And I perform the one-way anova pot using this code:
a <- aov( value ~ label, data)
summary(a)
Which produces:
Df Sum Sq Mean Sq F value Pr(>F)
label 1 4.201 4.201 4.793 0.042 *
Residuals 18 15.779 0.877
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Notice the p-value is 0.042.
However when I tried with ggsignif with this code:
ggplot(data, aes(x = label, y = value )) +
geom_boxplot() +
geom_signif(comparison = list(c("A", "B")), y_position = 11, test = function(a, b) {
list(p.value = summary(aov(a ~ b))[[1]][["Pr(>F)"]][[1]])
})
I got this:
Note the p-value stated there is 0.28 instead of 0.042. What's the right way to do it, so that I can put the 0.042 value inside the plot?