1

I have a histogram I created in ggplot2 and added pairwise comparisons with adjusted p-values using the stat_pvalue_manual function from ggpubr.

pwc <- df_melt %>%
  wilcox_test(value ~ variable, paired = TRUE, p.adjust.method = "holm")

ggplot(df, aes(x = reorder(variable, -value), y = value)) +
  stat_summary(fun = mean, geom = "bar", fill = "#9E0142", width = 0.75) +
  stat_summary(fun.data = mean_cl_boot, geom = "errorbar",
               colour="black", position=position_dodge(1), width=.2) + 
  stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.02, step.increase = 0.1, hide.ns = TRUE, y.position = c(5, 5.25, 5.5, 5.75, 6, 6.25, 6.5, 6.75), label.size = 3)

This produces the following graph

enter image description here

I would like to reorder the brackets so that they look a bit nicer, for example having the init_com_rank and battery_rank comparison first, then init_com_rank and com_interrupted rank etc etc. how can I do this? I tried manually reordering the positions in y.position to c(5.5, 5.75, 5, 5.25, 6.5, 6.75, 6, 6.25) but this did not work (see below)

enter image description here

I am thinking one solution would be to somehow reorder the output in the pwc table directly, but I am also not sure how to do this.

becbot
  • 151
  • 1
  • 2
  • 9

0 Answers0