title: Creating donut charts with ggplot2 and grouping variables
body: <p>apologies if this has already been answered but I've tried code from many posts to no avail. I am trying to make a donut chart in ggplot 2, which is new for me. It seems to be working for the most part, but isnt grouping the countries together, so instead each row gets its own chunk in the pie chart, instead of all UK rows being put together (sorry if thats a bit rambly).</p>
  
  <p>Heres the code with some example data (i actually have 14 countries and 1200 rows):</p>
  
  <pre><code>  country &lt;- c("Australia", "Australia", "China", "UK", "UK", "UK", "Australia", "New Zealand", "Hong Kong", "India", "India", "Korea", "Malaysia", "UK")
    GAV &lt;- c(32626614, 611751827, 1070038943.77, 1070038990, 611751347, 567751827, 444751827, 611751444, 999751827, 111751827, 222751827, 331751827, 611751844, 611777827)
  
  panel_donut &lt;- data.frame(country, GAV)
  </code></pre>
  
  <h3>remove rows with NA GAV</h3>
  
  <pre><code>panel_donut &lt;- panel_donut[!is.na(panel_donut$GAV),]
  </code></pre>
  
  <h2>calculate percentage</h2>
  
  <pre><code>panel_donut$percentage &lt;-  panel_donut$GAV / sum(panel_donut$GAV)* 100
  
  panel_donut &lt;-  panel_donut[rev(order(panel_donut$percentage)), ]
  
  panel_donut$ymax &lt;-  cumsum(panel_donut$percentage)
  
  panel_donut$ymin &lt;-  c(0, head(panel_donut$ymax, n = -1))
  
  panel_donut
  </code></pre>
  
  <h1>reorder colour levels</h1>
  
  <pre><code>panel_donut &lt;-  panel_donut[order(panel_donut$country), ]
  </code></pre>
  
  <h2>plot the chart</h2>
  
  <pre><code>library(ggplot2)
  library(ggrepel)
  
  donut &lt;-  ggplot(panel_donut, aes(fill = country, ymax = ymax, ymin = ymin, xmax = 100, xmin = 80)) +
  
    geom_rect(colour = "black") +
  
    coord_polar(theta = "y") + 
  
    xlim(c(0, 100)) +
  
    theme(legend.title = element_text(colour = "black", size = 16, face = "bold"), 
      legend.text = element_text(colour = "black", size = 15), 
      panel.grid = element_blank(),
      axis.text = element_blank(),
      axis.title = element_blank(),
      axis.ticks = element_blank())
  
  donut
  </code></pre>
  
  <p>Currently, I get a donut chart but all of the levels have separate chunks, i.e UK has 4 chunks of the donut instead of it being grouped into 1. I'm wondering where I have gone wrong in my code that has resulted in this happening. </p>
  
  <p>Thanks in advance for any help!</p>