title: ggplot2: stacked barplot over different columns
body: <p>I have the following sample data with three different cost-types and a year-column:</p>
  
  <pre><code>library(tidyverse)
  
  # Sample data
  costsA &lt;- sample(100:200,30, replace=T)
  costsB &lt;- sample(100:140,30, replace=T)
  costsC &lt;- sample(20:20,30, replace=T)
  year &lt;- sample(c("2000", "2010", "2030"), 30, replace=T)
  df &lt;- data.frame(costsA, costsB, costsC, year)
  </code></pre>
  
  <p>My goal is to plot these costs in a stacked barplot, so that I can compare the mean-costs between the three year-categories. In order to do so I aggregated the values:</p>
  
  <pre><code>df %&gt;% group_by(year) %&gt;%
    summarise(n=n(),
              meanA = mean(costsA),
              meanB = mean(costsB),
              meanC = mean(costsC)) %&gt;%
  ggplot( ... ) + geom_bar()
  </code></pre>
  
  <p>But how can I plot the graph now? In the x-axis there should be the years and in the y-axis the stacked costs.</p>
  
  <p><img src="https://i.stack.imgur.com/kIGHp.jpg" alt="example"></p>