title: How to control the bar width of a grouped bar chart in ggplot2?
body: <p><strong>data</strong></p>
  <pre><code>structure(list(MutationsType = c(&quot;0:homdel:0-100kb&quot;, &quot;1:LOH:1Mb-10Mb&quot;, 
  &quot;1:LOH:1Mb-10Mb&quot;, &quot;1:LOH:10Mb-40Mb&quot;, &quot;0:homdel:0-100kb&quot;, &quot;1:LOH:0-100kb&quot;, 
  &quot;0:homdel:100kb-1Mb&quot;, &quot;0:homdel:0-100kb&quot;, &quot;1:LOH:0-100kb&quot;, &quot;0:homdel:0-100kb&quot;, 
  &quot;1:LOH:10Mb-40Mb&quot;, &quot;1:LOH:10Mb-40Mb&quot;, &quot;0:homdel:100kb-1Mb&quot;, &quot;1:LOH:0-100kb&quot;, 
  &quot;0:homdel:100kb-1Mb&quot;, &quot;1:LOH:100kb-1Mb&quot;, &quot;1:LOH:100kb-1Mb&quot;, &quot;1:LOH:10Mb-40Mb&quot;, 
  &quot;0:homdel:0-100kb&quot;, &quot;1:LOH:0-100kb&quot;, &quot;1:LOH:1Mb-10Mb&quot;, &quot;1:LOH:100kb-1Mb&quot;, 
  &quot;1:LOH:10Mb-40Mb&quot;, &quot;0:homdel:&gt;1Mb&quot;, &quot;0:homdel:100kb-1Mb&quot;, &quot;0:homdel:100kb-1Mb&quot;, 
  &quot;1:LOH:1Mb-10Mb&quot;, &quot;1:LOH:0-100kb&quot;, &quot;0:homdel:100kb-1Mb&quot;, &quot;0:homdel:&gt;1Mb&quot;, 
  &quot;1:LOH:0-100kb&quot;, &quot;0:homdel:100kb-1Mb&quot;, &quot;1:LOH:1Mb-10Mb&quot;, &quot;0:homdel:&gt;1Mb&quot;, 
  &quot;0:homdel:0-100kb&quot;, &quot;0:homdel:&gt;1Mb&quot;, &quot;1:LOH:0-100kb&quot;, &quot;0:homdel:0-100kb&quot;, 
  &quot;0:homdel:0-100kb&quot;, &quot;0:homdel:&gt;1Mb&quot;, &quot;0:homdel:&gt;1Mb&quot;, &quot;1:LOH:1Mb-10Mb&quot;, 
  &quot;1:LOH:1Mb-10Mb&quot;, &quot;1:LOH:0-100kb&quot;, &quot;1:LOH:100kb-1Mb&quot;, &quot;1:LOH:1Mb-10Mb&quot;, 
  &quot;1:LOH:1Mb-10Mb&quot;, &quot;0:homdel:&gt;1Mb&quot;, &quot;0:homdel:0-100kb&quot;), CN = c(&quot;0&quot;, 
  &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, 
  &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, 
  &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, 
  &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;), Type = c(&quot;homdel&quot;, 
  &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, 
  &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, 
  &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;homdel&quot;, &quot;LOH&quot;, 
  &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, 
  &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, 
  &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;, &quot;LOH&quot;
  ), Size = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
  2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 
  1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
  5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c(&quot;0-100kb&quot;, &quot;100kb-1Mb&quot;, 
  &quot;&gt;1Mb&quot;, &quot;1Mb-10Mb&quot;, &quot;10Mb-40Mb&quot;, &quot;&gt;40Mb&quot;), class = &quot;factor&quot;), 
      MutSig = c(&quot;CCN1&quot;, &quot;CCN2&quot;, &quot;CCN3&quot;, &quot;CCN4&quot;, &quot;CCN5&quot;, &quot;CCN6&quot;, 
      &quot;CCN7&quot;, &quot;CCN1&quot;, &quot;CCN2&quot;, &quot;CCN3&quot;, &quot;CCN4&quot;, &quot;CCN5&quot;, &quot;CCN6&quot;, &quot;CCN7&quot;, 
      &quot;CCN1&quot;, &quot;CCN2&quot;, &quot;CCN3&quot;, &quot;CCN4&quot;, &quot;CCN5&quot;, &quot;CCN6&quot;, &quot;CCN7&quot;, &quot;CCN1&quot;, 
      &quot;CCN2&quot;, &quot;CCN3&quot;, &quot;CCN4&quot;, &quot;CCN5&quot;, &quot;CCN6&quot;, &quot;CCN7&quot;, &quot;CCN1&quot;, &quot;CCN2&quot;, 
      &quot;CCN3&quot;, &quot;CCN4&quot;, &quot;CCN5&quot;, &quot;CCN6&quot;, &quot;CCN7&quot;, &quot;CCN1&quot;, &quot;CCN2&quot;, &quot;CCN3&quot;, 
      &quot;CCN4&quot;, &quot;CCN5&quot;, &quot;CCN6&quot;, &quot;CCN7&quot;, &quot;CCN1&quot;, &quot;CCN2&quot;, &quot;CCN3&quot;, &quot;CCN4&quot;, 
      &quot;CCN5&quot;, &quot;CCN6&quot;, &quot;CCN7&quot;), Contribution = c(5.19e-06, 1.3e-07, 
      1.9e-07, 0.08029968, 4e-08, 9.22e-05, 7e-08, 0.01464032, 
      0.00180809, 1.5e-07, 0.05639156, 0.00649378, 1.9e-07, 0.00031971, 
      0.01814325, 0.00706934, 1.3e-07, 0.00210131, 0.00096393, 
      0.00031971, 0.00051292, 0.00707025, 0.00075506, 0.03741672, 
      0.01814325, 0.00149914, 9.22e-05, 1.1e-07, 0.02898539, 0.00051292, 
      1.556e-05, 0.01435299, 0.01814325, 7.439e-05, 0.00048986, 
      1.5e-07, 0.00149914, 7.439e-05, 7.913e-05, 0.03741672, 0.01435299, 
      0.00707025, 0.00031971, 0.00740625, 0.02898539, 1.7e-06, 
      0.01435299, 1.9e-07, 9.22e-05), Race = c(&quot;CBCGA&quot;, &quot;CBCGA&quot;, 
      &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, 
      &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, 
      &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, 
      &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, 
      &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, 
      &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, 
      &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;, &quot;CBCGA&quot;), Type2 = structure(c(1L, 
      1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
      1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
      2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
      2L, 2L, 2L), .Label = c(&quot;homdel:0&quot;, &quot;LOH:1&quot;, &quot;LOH:2&quot;, &quot;LOH:3-4&quot;, 
      &quot;LOH:5-8&quot;, &quot;LOH:9+&quot;, &quot;het:2&quot;, &quot;het:3-4&quot;, &quot;het:5-8&quot;, &quot;het:9+&quot;
      ), class = &quot;factor&quot;)), row.names = c(NA, -49L), class = c(&quot;tbl_df&quot;, 
  &quot;tbl&quot;, &quot;data.frame&quot;))
  </code></pre>
  <p>I have drawn a grouped bar chart using the data above with the following code.</p>
  <pre><code>ggplot(tmpdf, aes(x = Type2, y = Contribution, fill = Size)) +
    geom_bar(stat = &quot;identity&quot;, position = 'dodge', width = 0.8) + 
    scale_x_discrete('') + 
    scale_y_continuous(expand = c(0, 0)) +
    theme(panel.background = element_blank(),
          plot.background = element_blank(),
          panel.grid.major = element_blank(), 
          panel.grid.minor = element_blank(),
          axis.line.x = element_line(size = 0.25),
          axis.line.y = element_blank(),
          axis.ticks.x = element_line(size = 0.25),
          axis.ticks.y = element_blank(),
          axis.title = element_text(size = 12),
          axis.text.y = element_text(size = 10),
          axis.text.x = element_text(size = 10))
  </code></pre>
  <p>And I got a bar chart below. We can see that the bar width of the first group &quot;homodel:0&quot; was different from the width of the second group due to different levels of the fill variable. <strong>I want to know how to control the bar width in this condition and make them the same between two groups.</strong>
  <a href="https://i.stack.imgur.com/GZYmr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GZYmr.png" alt="enter image description here" /></a></p>