title: How to show percentages in stacked column with ggplot geom_bar?
body: <p>I'm trying to add percentage labels in a stacked bar chart. What can I add to my geom_bar to show the percentage labels inside stacked bars?</p>
  
  <p>This is my data:</p>
  
  <pre><code>myresults=data.frame(
      manipulation=rep(c(-20,-10,0,10,20,-20,-10,0,10,20,-20,-10,0,10,20)),
      variable=rep(c("a","a","a","a","a","f","f","f","f","f","l","l","l","l","l")),
      value=c(73,83,76,75,78,261,301,344,451,599,866,816,780,674,523))
  </code></pre>
  
  <p><a href="https://i.imgur.com/VUvx1hz.png" rel="nofollow noreferrer">This is my bar chart, without percentage labels.</a></p>
  
  <p>I have little knowledge in this. I googled "gglot stacked bar percentage label" and found that adding percentage labels could be done with "+ geom_text(stat="count")".</p>
  
  <p>But when I added + geom_text(stat="count") to my ggplot geom_bar, R said "Error: stat_count() must not be used with a y aesthetic." I tried to figure out what a y aesthetic is, but it hasn't been very successful.</p>
  
  <p>This is what I did:</p>
  
  <pre><code>mydata &lt;- ggplot(myresults, aes(x=manipulation, y=value, fill=variable))
  
  mydata + geom_bar(stat="identity", position="fill", colour="black") + scale_fill_grey() + scale_y_continuous(labels=scales::percent) + theme_bw(base_family="Cambria") + labs(x="Manipulation", y=NULL, fill="Result") + theme(legend.direction="vertical", legend.position="right")
  </code></pre>