text: user4595: I have 3 data frames for three groups of patients and in each of them I have the number of mutation types like insertion, deletion, SNP and total of mutations for each patients. In each group I have different number of patients like below
  > head(dat1)
                  patient  DEL  INS   SNP   total
  1:    LP6008337-DNA_H06  927  773 40756   42456
  2:    LP6008334-DNA_D02 1049  799 31009   32857
  > dim(dat1)
  [1] 21  6
  > 
  
   head(dat2)
                  Patient   DEL  INS   SNP total
  1:    LP6008031-DNA_E01 13552 3374 62105   79031
  2:    LP6005500-DNA_G01   539  500 43451   44490
  > dim(dat2)
  [1] 33  6
  > 
  
  > head(dat3)
                  Patient   DEL   INS    SNP    total
  1:    LP6005935-DNA_F03 39168 16739  58095   114002
  2:    LP6008269-DNA_D08   849   910 103501  105271
  
  > dim(dat3)
  [1] 106   6
  
  I want to show if the number of each mutational category and total is different between these three groups by chi-square test
  Actual question is if total number of mutations, SNP, DEL and INS are statistically significant among groups. I used pairwise t test but I afraid this test is not a suitable test for the distribution of data moreover I don't know how to visualize the p-value
  Imagining the comparison of total number of mutations between three groups, this picture is a good example
  
  Or in this plot they compare several features but only two groups 
  
  Can you help ?
  Thanks 
  
  user6437: Here a way to do it is to start first by creating a dataset containing your three different group, based on the few lines you display:
  dat1$Condition = "dat1"
  dat2$Condition = "dat2"
  dat3$Condition = "dat3"
  colnames(dat1)[1] = "Patient"
  DF <- rbind(dat1,dat2,dat3)
  
               Patient   DEL   INS    SNP  total Condition
  1: LP6008337-DNA_H06   927   773  40756  42456      dat1
  2: LP6008334-DNA_D02  1049   799  31009  32857      dat1
  3: LP6008031-DNA_E01 13552  3374  62105  79031      dat2
  4: LP6005500-DNA_G01   539   500  43451  44490      dat2
  5: LP6005935-DNA_F03 39168 16739  58095 114002      dat3
  6: LP6008269-DNA_D08   849   910 103501 105271      dat3
  
  Then, you can reshape DF in order to put all values DEL, INS, SNP and Total into a single column and create a categorical column. Doing this will be helpful for later producing the facets of your plot. To do that, you can use pivot_longer from tidyr package:
  library(tidyr)
  DF <- DF %>% pivot_longer(.,cols = c(DEL,INS,SNP, total), names_to = "var", values_to = "val")
  
  # A tibble: 24 x 4
     Patient           Condition var     val
     <chr>             <chr>     <chr> <int>
   1 LP6008337-DNA_H06 dat1      DEL     927
   2 LP6008337-DNA_H06 dat1      INS     773
   3 LP6008337-DNA_H06 dat1      SNP   40756
   4 LP6008337-DNA_H06 dat1      total 42456
   5 LP6008334-DNA_D02 dat1      DEL    1049
   6 LP6008334-DNA_D02 dat1      INS     799
   7 LP6008334-DNA_D02 dat1      SNP   31009
   8 LP6008334-DNA_D02 dat1      total 32857
   9 LP6008031-DNA_E01 dat2      DEL   13552
  10 LP6008031-DNA_E01 dat2      INS    3374
  # … with 14 more rows
  
  Now, you can plot your data and use the function stat_compare_means from ggpubr package to get the significance display on each tab. Based on the size of your group, you may want to adjust for the type of statistical test to be used (take a look at ?stat_compare_means to find the statistical test adequate to your dataset). You can pass various conditions to test as a list by using comparisons argument. 
  For facetting your graph, you can use facet_grid (orfacet_wrap, try the one you preferred). Altogether, you can get the plot by writing:
  library(ggplot2)
  library(ggpubr)
  ggplot(DF, aes(x = Condition, y = val, fill = Condition))+
    geom_boxplot()+
    stat_compare_means(comparisons = list(c("dat1","dat2"), c("dat1","dat3"), c("dat2","dat3")))+
    stat_compare_means()+
    facet_grid(var~., scales = "free")
  
  
  Hope it helps you to figure it out how to represent your data.
  
original_text: 4595: <p>I have 3 data frames for three groups of patients and in each of them I have the number of mutation types like insertion, deletion, SNP and total of mutations for each patients. In each group I have different number of patients like below</p>
  
  <pre><code>&gt; head(dat1)
                  patient  DEL  INS   SNP   total
  1:    LP6008337-DNA_H06  927  773 40756   42456
  2:    LP6008334-DNA_D02 1049  799 31009   32857
  &gt; dim(dat1)
  [1] 21  6
  &gt; 
  
   head(dat2)
                  Patient   DEL  INS   SNP total
  1:    LP6008031-DNA_E01 13552 3374 62105   79031
  2:    LP6005500-DNA_G01   539  500 43451   44490
  &gt; dim(dat2)
  [1] 33  6
  &gt; 
  
  &gt; head(dat3)
                  Patient   DEL   INS    SNP    total
  1:    LP6005935-DNA_F03 39168 16739  58095   114002
  2:    LP6008269-DNA_D08   849   910 103501  105271
  
  &gt; dim(dat3)
  [1] 106   6
  </code></pre>
  
  <p>I want to show if the number of each mutational category and total is different between these three groups by chi-square test</p>
  
  <p>Actual question is if total number of mutations, SNP, DEL and INS are statistically significant among groups. I used pairwise t test but I afraid this test is not a suitable test for the distribution of data moreover I don't know how to visualize the p-value</p>
  
  <p>Imagining the comparison of total number of mutations between three groups, this picture is a good example
  <a href="https://i.stack.imgur.com/ABR04.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ABR04.jpg" alt="enter image description here"></a></p>
  
  <p>Or in this plot they compare several features but only two groups </p>
  
  <p><a href="https://i.stack.imgur.com/Sy4cn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Sy4cn.jpg" alt="enter image description here"></a></p>
  
  <p>Can you help ?</p>
  
  <p>Thanks </p>
   6437: <p>Here a way to do it is to start first by creating a dataset containing your three different group, based on the few lines you display:</p>
  
  <pre class="lang-r prettyprint-override"><code>dat1<span class="math-container">$Condition = "dat1"
  dat2$</span>Condition = "dat2"
  dat3$Condition = "dat3"
  colnames(dat1)[1] = "Patient"
  DF &lt;- rbind(dat1,dat2,dat3)
  
               Patient   DEL   INS    SNP  total Condition
  1: LP6008337-DNA_H06   927   773  40756  42456      dat1
  2: LP6008334-DNA_D02  1049   799  31009  32857      dat1
  3: LP6008031-DNA_E01 13552  3374  62105  79031      dat2
  4: LP6005500-DNA_G01   539   500  43451  44490      dat2
  5: LP6005935-DNA_F03 39168 16739  58095 114002      dat3
  6: LP6008269-DNA_D08   849   910 103501 105271      dat3
  </code></pre>
  
  <p>Then, you can reshape <code>DF</code> in order to put all values DEL, INS, SNP and Total into a single column and create a categorical column. Doing this will be helpful for later producing the facets of your plot. To do that, you can use <code>pivot_longer</code> from <code>tidyr</code> package:</p>
  
  <pre class="lang-r prettyprint-override"><code>library(tidyr)
  DF &lt;- DF %&gt;% pivot_longer(.,cols = c(DEL,INS,SNP, total), names_to = "var", values_to = "val")
  
  # A tibble: 24 x 4
     Patient           Condition var     val
     &lt;chr&gt;             &lt;chr&gt;     &lt;chr&gt; &lt;int&gt;
   1 LP6008337-DNA_H06 dat1      DEL     927
   2 LP6008337-DNA_H06 dat1      INS     773
   3 LP6008337-DNA_H06 dat1      SNP   40756
   4 LP6008337-DNA_H06 dat1      total 42456
   5 LP6008334-DNA_D02 dat1      DEL    1049
   6 LP6008334-DNA_D02 dat1      INS     799
   7 LP6008334-DNA_D02 dat1      SNP   31009
   8 LP6008334-DNA_D02 dat1      total 32857
   9 LP6008031-DNA_E01 dat2      DEL   13552
  10 LP6008031-DNA_E01 dat2      INS    3374
  # … with 14 more rows
  </code></pre>
  
  <p>Now, you can plot your data and use the function <code>stat_compare_means</code> from <code>ggpubr</code> package to get the significance display on each tab. Based on the size of your group, you may want to adjust for the type of statistical test to be used (take a look at <code>?stat_compare_means</code> to find the statistical test adequate to your dataset). You can pass various conditions to test as a list by using <code>comparisons</code> argument. </p>
  
  <p>For facetting your graph, you can use <code>facet_grid</code> (or<code>facet_wrap</code>, try the one you preferred). Altogether, you can get the plot by writing:</p>
  
  <pre class="lang-r prettyprint-override"><code>library(ggplot2)
  library(ggpubr)
  ggplot(DF, aes(x = Condition, y = val, fill = Condition))+
    geom_boxplot()+
    stat_compare_means(comparisons = list(c("dat1","dat2"), c("dat1","dat3"), c("dat2","dat3")))+
    stat_compare_means()+
    facet_grid(var~., scales = "free")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/LAuWd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LAuWd.png" alt="enter image description here"></a></p>
  
  <p>Hope it helps you to figure it out how to represent your data.</p>
  