Closed gundalav closed 4 years ago
Hi gundalav,
thank you for the detailed and easy to reproduce question.
The problem is that arguments a
and b
in the test=function(a, b){...}
work slightly different than you assume. The easiest way to see this is to add browser()
call inside the function like this (which is actually a super-powerful general way to debug problems):
ggplot(data, aes(x = label, y = value )) +
geom_boxplot() +
geom_signif(comparison = list(c("A", "B")), y_position = 11, test = function(a, b) {
browser()
list(p.value = summary(aov(a ~ b))[[1]][["Pr(>F)"]][[1]])
})
To get the p-value that you expect, you would have to do the following:
ggplot(data, aes(x = label, y = value )) +
geom_boxplot() +
geom_signif(comparison = list(c("A", "B")), y_position = 11, test = function(a, b) {
tmp_label <- c(rep("A", length(a)), rep("B", length(b)))
tmp_values <- c(a, b)
list(p.value = summary(aov(tmp_values ~ tmp_label))[[1]][["Pr(>F)"]][[1]])
})
Best, Constantin
Thank you. That does it.
I have the following data
And I perform the one-way anova pot using this code:
Which produces:
Notice the p-value is 0.042.
However when I tried with ggsignif with this code:
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?