Adding significance values from Dunnett's test to ggplot (bar)

mydata

A tibble: 9 x 2

group value

1 control 100
2 control 101
3 control 99
4 apples 48
5 apples 49
6 apples 50
7 pears 30
8 pears 29
9 pears 28

DunnettTest(mydata$value ~ as.factor(mydata$group), control = "control")

Dunnett's test for comparing several treatments with a control :
95% family-wise confidence level

$control
diff lwr.ci upr.ci pval
apples-control -51 -53.34006 -48.65994 2.1e-09 ***
pears-control -71 -73.34006 -68.65994 2.8e-10 ***


Signif. codes: 0 '' 0.001 '' 0.01 '' 0.05 '.' 0.1 ' ' 1

How can I automatically add the level of significance (number of asterisks in the pval column) to my ggplot, where the *** is above the bars for apples and pears.

Hi @daisyb. You may try to take a look at ggsignif package see if it can help you.