I am using R to add some p-values to boxplots. I would like to specifically compare pairs of boxplots using a wilcoxon rank sum test. I tried using the function statcomparemeans() from ggpubr but unfortunately there is no option to add adjusted p-values. I searched online for a bit and noticed a function from the same package called statpvaluemanual() which would allow me to put the p-values in. However, I have not been able to figure out the package.
I am using the tooth growth data from R as an example:
library(dplyr) library(ggplot2) library(rstatix) library(ggpubr) ToothGrowth$dose=as.factor(ToothGrowth$dose) #Boxplot ToothGrowth%>%ggplot(aes(x=dose, y=len, fill=supp))+ geom_boxplot()
I would like to do a wilcoxon sum rank test on the data and label each comparison between OJ and VC.
Below is the stats test, which when I check it corresponds to the three comparisons I want between OJ and VC:
#Wilcoxon Ranked Sum stats test stat.test <- ToothGrowth%>%group_by(dose)%>%wilcox_test(len~supp, p.adjust.method = 'BH')%>% mutate(y.position = c(29, 35, 39))
However, when I try to add this to my boxplot I get an error:
#Add p-values ToothGrowth%>%ggplot(aes(x=dose, y=len, fill=supp))+ geom_boxplot()+ stat_pvalue_manual(stat.test, label = 'p') #Error Error in FUN(X[[i]], ...) : object 'supp' not found
What I think is happening is that it is using the aes() from ggplot and when it can't find 'supp' it is running into an error, but when I set inherit.aes=false within the statpvaluemanual function, OJ and VC end up in the x-axis and it a weird comparison between the two groups instead of the boxplots. I have been trying for hours to figure out what I am doing wrong but I have had no luck so far.