title: Adding t-test value to grouped data set in r
body: <p>When running <code>stat_compare_means</code> I am unable to run a t-test. If I leave the brackets empty it will attempt a Wilcoxen but I don't think it is accurate.
  I have tried editing several settings under <code>stat_compare_means</code> and tried changing to using <code>geom_signif</code> but have gotten a variety of different results.</p>
  <p>Note: The data needs to be grouped this way as there are other groups I have left out.</p>
  <pre><code>#functions
  se = function(x) {
    sd(x)/sqrt(length(x))
  }
  
  data_summary &lt;- function(x) {
    m &lt;- mean(x)
    ymin &lt;- m-sd(x)
    ymax &lt;- m+sd(x)
    return(c(y=m,ymin=ymin,ymax=ymax))
  }
  
  plot.mean &lt;- function(x) {
    m &lt;- mean(x)
    c(y = m, ymin = m, ymax = m)
  }
  </code></pre>
  <pre><code>#data set
  HET.MOUSE.P
  Mouse Brca1 Sex       Tx     Stage Count
   001  fl/+   M OLAPARIB AnnexinV+ 33.90
   002  fl/+   F     DMSO AnnexinV+ 44.20
   003   -/+   F OLAPARIB AnnexinV+ 40.00
   004   -/+   M     DMSO AnnexinV+ 32.60
   005   -/+   M OLAPARIB AnnexinV+ 34.80
   006   -/+   M OLAPARIB AnnexinV+ 21.82
   007  fl/+   F OLAPARIB AnnexinV+ 27.09
   008   -/+   F OLAPARIB AnnexinV+ 30.92
   009  fl/+   M     DMSO AnnexinV+  4.82
   010   -/+   M     DMSO AnnexinV+  3.97
   011   -/+   F     DMSO AnnexinV+  3.01
   012   -/+   F     DMSO AnnexinV+  2.91
   013   -/+   M     DMSO AnnexinV+  2.42
   014   -/+   M     DMSO AnnexinV+  4.15
   015   -/+   M OLAPARIB AnnexinV+  4.28
  </code></pre>
  <pre><code>#plot code
  HET.MOUSE.P.perT.med &lt;- aggregate(Count ~ Stage + Tx, data = HET.MOUSE.P, median)
      HET.MOUSE.P.perT.med &lt;- HET.MOUSE.P.perT.med %&gt;%
        rename(med = Count)
      HET.MOUSE.P.perT.med
      HET.MOUSE.P.perT.se &lt;- aggregate(Count ~ Stage + Tx, data = HET.MOUSE.P, se)
      HET.MOUSE.P.perT.se &lt;- HET.MOUSE.P.perT.se %&gt;%
        rename(se = Count)
      HET.MOUSE.P.perT.se
      
      HET.MOUSE.P.perT.simp &lt;- merge(HET.MOUSE.P.perT.med, HET.MOUSE.P.perT.se)
      HET.MOUSE.P.perT.simp[is.na(HET.MOUSE.P.perT.simp)] &lt;- 0
      HET.MOUSE.P.perT.simp  
      
      HET.MOUSE.P$Stage &lt;-factor(HET.MOUSE.P$Stage)
      HET.MOUSE.P$Stage &lt;-factor(HET.MOUSE.P$Stage, levels = c(&quot;AnnexinV+&quot;))
      HET.MOUSE.P.perT.simp$Stage &lt;-factor(HET.MOUSE.P.perT.simp$Stage, levels = c(&quot;AnnexinV+&quot;))
     
      MOUSE.ttest &lt;- compare_means(data = HET.MOUSE.P, Count~Tx, method = &quot;t.test&quot;, paired = FALSE, group.by = &quot;Stage&quot;)
       
       HET.MOUSE.P.perT.barplot = ggplot(HET.MOUSE.P.perT.simp, aes(x = Stage, y = med, fill = Tx)) +
        geom_bar(stat=&quot;identity&quot;, color=&quot;black&quot;, 
                 position=position_dodge()) +
        geom_point(data = HET.MOUSE.P, aes(x = Stage, y = Count, fill = Tx), 
                   color = &quot;white&quot;, pch=21, size= 3, position = position_dodge(width = .9), show.legend = FALSE) +
        geom_errorbar(aes(ymin = med, ymax=med+se), width=.2,
                      position=position_dodge(.9)) +
        scale_fill_manual(values = c(&quot;darkblue&quot;, &quot;deepskyblue1&quot;)) +
        scale_shape_manual(values = c(0, 2)) +
        scale_x_discrete(limits=c(&quot;AnnexinV+&quot;)) +
        labs(x = NULL, y = &quot;% Total Cells&quot;, fill =&quot;Treatment&quot;, cex.lab = 5) +
        theme_classic() + ylim(0,50) +
        theme(text = element_text(family = &quot;Arial&quot;),
              plot.title = element_text(size = 16, hjust = 0.5, face = &quot;bold&quot;),
              axis.title.y = element_text(size = 12, face = &quot;bold&quot;),
              axis.text.x = element_text(size = 10, color = &quot;black&quot;), 
              axis.text.y = element_text(size = 14, color = &quot;black&quot;),
              axis.line = element_line(color = &quot;Black&quot;),
              legend.title = element_text(size = 11),
              legend.text = element_text(size = 11),
              legend.position = 'right',
              legend.justification = c(-0.05,-0.05)) +
         stat_compare_means(method = &quot;t.test&quot;)
  
      HET.MOUSE.P.perT.barplot 
  </code></pre>
  <p>After running this I get the error message:</p>
  <p>Warning message:
  Computation failed in <code>stat_compare_means()</code>:
  Problem while computing <code>p = purrr::map(...)</code>.</p>