title: Adding percentages for the whole group in a stacked ggplot2 bar chart
body: <p>I am trying to add group percentages via <code>geom_text()</code> in a stacked ggplot2 bar chart with counts on the y-axis. I have already seen and read <a href="https://stackoverflow.com/questions/35762468/adding-percentages-to-a-grouped-barchart-columns-in-ggplot2">this question</a> over here, but I don't think it gets me the solution.</p>
  
  <p>Here is a reproducible example:</p>
  
  <pre><code>library(ggplot2)
  library(scales)
  
  df &lt;- data.frame(Var1 = rep(c("A", "B", "C"), each = 3),
                   Var2 = rep(c("Gr1", "Gr2", "Gr3"), 3),
                   Freq = c(10, 15, 5, 5, 4, 3, 2, 10, 15))
  
  ggplot(df) + aes(x = Var2, y = Freq, fill = Var1) +
    geom_bar(stat = "identity") +
    geom_text(aes(y = ..count.., label = scales::percent(..count../sum(..count..))),
              stat = "count")
  </code></pre>
  
  <p>This is the result:</p>
  
  <p><a href="https://i.stack.imgur.com/aBqyk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aBqyk.png" alt="stacked bar chart"></a></p>
  
  <p>Just to be sure you understand what I want: I want the percentage of each group Gr1, Gr2, Gr3 above each bar, summing up to 100%.</p>
  
  <p>Basically, these would be the values I get when I do:</p>
  
  <pre><code>prop.table(tapply(df$Freq, df$Var2, sum))
  </code></pre>
  
  <p>Thanks!</p>