title: R Stacked Bar Percentage of Total
body: <p>I have a dataset that looks like this:</p>
  
  <pre><code>colour  week    value
  Blue    201523  374
  Blue    201524  310
  Blue    201525  300
  Green   201523  1951
  Green   201524  2299
  Green   201525  2111
  Red     201523  414
  Red     201524  361
  Red     201525  279
  </code></pre>
  
  <p>I wish to produce a stacked plot with percentage of total value vs time grouped by colour.</p>
  
  <p>The following code gives the correct plot but with absolute values rather than percentage of total (dataset saved as df):</p>
  
  <pre><code>  g &lt;- ggplot(data = df)
    g &lt;- g + geom_bar(stat = 'identity', aes(x = Time, y = value, fill = Colour)) + scale_y_continuous(labels = percent)
    g &lt;- g + labs(x = 'Timespan', y = '') + guides(fill = guide_legend(reverse = FALSE))
      theme(legend.text = element_text(size = 12), axis.title.x = element_text(size = 14, vjust = -0.5, face = 'bold'), legend.title = element_text(size = 14),
            axis.text.x = element_text(angle = 45, size = 10.5))
    g
  </code></pre>
  
  <p>Is there a way of obtaining the percentage of total within the call to ggplot? Or if not is it possible to do this using a ddply function before the ggplot call? </p>