Question: (Closed) Manually adding corrected p-values to boxplots in R
gravatar for ravelarvargas
3 months ago by
ravelarvargas0 wrote:

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:



ToothGrowth%>%ggplot(aes(x=dose, y=len, fill=supp))+

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))+
          stat_pvalue_manual(stat.test, label = 'p')

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.

R ggplot2 boxplot rstatix ggpubr • 203 views
ADD COMMENTlink written 3 months ago by ravelarvargas0

Hello ravelarvargas!

We believe that this post does not fit the main topic of this site.

This question isn't about bioconductor, so you should ask on r-help or stack overflow.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.


ADD REPLYlink written 3 months ago by James W. MacDonald51k
Please log in to add an answer.
The thread is closed. No new answers may be added.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 135 users visited in the last hour