This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Add stats to boxplot in R

Hi,

I need help to improve the stat on this plot. First, I am not sure how to move the Kruskal-wallis above the others pvalue. Then, I want to add line below the kruskal-wallis test?

I used this code to generate:

gv_interest = ggboxplot(dat_viogenes, x = "Condition", 
                      y = colnames(dat_viogenes)[1:19],
                      combine = T,
                      fill="Condition") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + 
  stat_compare_means(comparisons = my_comparisons,method = "wilcox.test",
                     label.y = 2.5,
                     method.args = list(alternative="greater"))+

   stat_compare_means(method = "kruskal.test", label.y = 2, size= 5, hjust= 0.09)

gv_interest

Any help would be much appreciated and thanks in advance

boxplot

stats r

1 answer

Hi,

Have you tried switching the order of the stat_compare_means for the Wilcox with the one for kruskall-Wallis ?

Great. thats work. Do you know how can I remove the kruskall-Wallis name from the plot? Also I would like to draw a line under the kruskall-Wallis P value? Is it possible to use symbol instead of p value ? Thanks very much for your helpenter image description here

To remove "Kruskall Wallis" you can try adding the argument label="p" or label = "p.signif" which displays the p-value or *** like this:

stat_compare_means(method = "kruskal.test", size = 5, hjust = 0.09, label = "p.signif")

Thanks. Thats work

Log in to answer this question.