title: Add percentage labels to a stacked barplot
body: <p>I have successfully made a stacked barplot in R where the percentages add up to 100% for several different categories. I made an example dataframe here.</p>
  
  <pre><code>example.Category&lt;- c("Cat1","Cat2","Cat3","Cat4","Cat5","Cat6")
  percent.good &lt;- c(.25,.29,.45,.5,.8,.82)
  example.data &lt;- data.frame(example.Category,percent.good)
  example.data$percent.bad &lt;- (1-example.data$percent.good)
  </code></pre>
  
  <p>The dataframe looks like this.    </p>
  
  <pre><code>     example.Category percent.good percent.bad
  1             Cat1         0.25        0.75
  2             Cat2         0.29        0.71
  3             Cat3         0.45        0.55
  4             Cat4         0.50        0.50
  5             Cat5         0.80        0.20
  6             Cat6         0.82        0.18
  </code></pre>
  
  <p>I then used melt from the reshape package to get this...</p>
  
  <pre><code>example.melt &lt;- melt(example.data, id.vars="example.Category")
  
     example.Category     variable value
  1              Cat1 percent.good  0.25
  2              Cat2 percent.good  0.29
  3              Cat3 percent.good  0.45
  4              Cat4 percent.good  0.50
  5              Cat5 percent.good  0.80
  6              Cat6 percent.good  0.82
  7              Cat1  percent.bad  0.75
  8              Cat2  percent.bad  0.71
  9              Cat3  percent.bad  0.55
  10             Cat4  percent.bad  0.50
  11             Cat5  percent.bad  0.20
  12             Cat6  percent.bad  0.18
  </code></pre>
  
  <p>Then I used ggplot to make a stacked barplot displaying these percentages.</p>
  
  <pre><code>ggplot(example.melt, aes(x=example.Category, y=value, fill = variable)) +
    geom_bar(position = "fill", stat = "identity",color='black',width=0.9) +
    scale_y_continuous(labels = scales::percent) +
    geom_text(aes(label = paste0((example.data$percent.good &amp;&amp; example.data$percent.bad)*100), '%'),position = position_dodge(width = .9),size = 3)
  </code></pre>
  
  <p>This yields this graph, which is what I want, except for the way it labels.
  <a href="https://i.stack.imgur.com/cGkeJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cGkeJ.jpg" alt="Graph"></a></p>
  
  <p>What I want to do is have percentage labels for each color on each stacked bar, and I have no idea how to do that and am certain that I didn't do it right. All I managed to do was somehow create another category that has some '100's around. How would I get the percent labels to appear on this graph for each part of the bar?</p>
  
  <p>I hope this isn't redundant/asked before. Thanks.</p>