title: R ggplot2 boxplots - ggpubr stat_compare_means not working properly
body: <p>I am trying to add significance levels to my <strong>boxplots</strong> in the form of asterisks using <strong>ggplot2</strong> and the <strong>ggpubr</strong> package, but I have many comparisons and I only want to show the significant ones.</p>
  
  <p>I try to use the option <strong><em>hide.ns=TRUE</em></strong> in <strong>stat_compare_means</strong>, but it clearly <strong>does not work</strong>, it might be a bug in the <strong>ggpubr</strong> package.</p>
  
  <p>Besides, you see that I leave out group "PGMC4" from the pairwise <strong>wilcox.test</strong> comparisons; how can I leave this group out also for the <strong>kruskal.test</strong>?</p>
  
  <p>The last question I have is how the significance level works? As in * is significant below 0.05, ** below 0.025, *** below 0.01? what is the convention ggpubr uses? Is it showing p-values or adjusted p-values? If the latter, what's the adjusting method? BH?</p>
  
  <p>Please check my MWE below and <a href="https://cran.r-project.org/web/packages/ggpubr/ggpubr.pdf" rel="nofollow noreferrer">this link</a> and <a href="http://www.sthda.com/english/wiki/add-p-values-and-significance-levels-to-ggplots#compare-more-than-two-groups" rel="nofollow noreferrer">this other one</a> for reference</p>
  
  <pre><code>##############################
  ##MWE
  set.seed(5)
  #test df
  mydf &lt;- data.frame(ID=paste(sample(LETTERS, 163, replace=TRUE), sample(1:1000, 163, replace=FALSE), sep=''),
                     Group=c(rep('C',10),rep('FH',10),rep('I',19),rep('IF',42),rep('NA',14),rep('NF',42),rep('NI',15),rep('NS',10),rep('PGMC4',1)),
                     Value=rnorm(n=163))
  #I don't want to compare PGMC4 cause I have only onw sample
  groups &lt;- as.character(unique(mydf$Group[which(mydf$Group!="PGMC4")]))
  #function to make combinations of groups without repeating pairs, and avoiding self-combinations
  expand.grid.unique &lt;- function(x, y, include.equals=FALSE){
      x &lt;- unique(x)
      y &lt;- unique(y)
      g &lt;- function(i){
          z &lt;- setdiff(y, x[seq_len(i-include.equals)])
          if(length(z)) cbind(x[i], z, deparse.level=0)
      }
      do.call(rbind, lapply(seq_along(x), g))
  }
  #all pairs I want to compare
  combs &lt;- as.data.frame(expand.grid.unique(groups, groups), stringsAsFactors=FALSE)
  head(combs)
  my.comps &lt;- as.data.frame(t(combs), stringsAsFactors=FALSE)
  colnames(my.comps) &lt;- NULL
  rownames(my.comps) &lt;- NULL
  #pairs I want to compare in list format for stat_compare_means
  my.comps &lt;- as.list(my.comps)
  head(my.comps)
  pdf(file="test.pdf", height=20, width=25)
  print(#or ggsave()
    ggplot(mydf, aes(x=Group, y=Value, fill=Group)) + geom_boxplot() +
      stat_summary(fun.y=mean, geom="point", shape=5, size=4) +
      scale_fill_manual(values=myPal) +
      ggtitle("TEST TITLE") +
      theme(plot.title = element_text(size=30),
        axis.text=element_text(size=12),
        axis.text.x = element_text(angle=45, hjust=1),
        axis.ticks = element_blank(),
        axis.title=element_text(size=20,face="bold"),
        legend.text=element_text(size=16)) +
    stat_compare_means(comparisons=my.comps, method="wilcox.test", label="p.signif", size=14) + #WHY DOES hide.ns=TRUE NOT WORK??? WHY DOES size=14 NOT WORK???
    stat_compare_means(method="kruskal.test", size=14) #GLOBAL COMPARISON ACROSS GROUPS (HOW TO LEAVE PGMC4 OUT OF THIS??)
  )
  dev.off()
  ##############################
  </code></pre>
  
  <p>The MWE will produce the following boxplots:</p>
  
  <p><a href="https://i.stack.imgur.com/MKlhT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MKlhT.png" alt="test"></a></p>
  
  <p>The questions would be:</p>
  
  <p>1- How to make hide.ns=TRUE work?</p>
  
  <p>2- How to increase the size of the *?</p>
  
  <p>3- How to exclude a group from the kruskal.test comparison?</p>
  
  <p>4- What is the * convention used by ggpubr, and are the p-values shown adjusted or not?</p>
  
  <p>Many thanks!!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Besides, when doing</p>
  
  <pre><code>stat_compare_means(comparisons=my.comps, method="wilcox.test", p.adjust.method="BH")
  </code></pre>
  
  <p>I do not obtain the same p-values as when doing</p>
  
  <pre><code>wilcox.test(Value ~ Group, data=mydf.sub)$p.value
  </code></pre>
  
  <p>where mydf.sub is a subset() of mydf for a given comparison of 2 groups.</p>
  
  <p>What is ggpubr doing here? How does it calculate the p.values?</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Please help, the solution does not have to be with ggpubr (but it has to be with <strong>ggplot2</strong>), I just need to be able to hide the NS and make the size of the asterisks bigger, as well as a p-value calculation identical to wilcox.test() + p.adjust(method"BH").</p>
  
  <p>Thanks!</p>