Count the number of occurances of values in ggplot
<p>I have the following data:</p>

<pre><code>df = data.frame(c("2012","2012","2012","2013"),
                c("tuesday","tuesday","friday","thursday"),
                c("AAA","BBB","AAA","AAA"))
colnames(df) = c("year","day","type")
</code></pre>

<p>I want to show the number of occurances (absolute frequency) of <code>type</code> values (AAA, BBB) per year and day.
Currently I wrote the following code, but it requires that I add one more dimension to <code>aes</code>, e.g. <code>aes(type, some_dimension, fill = as.factor(year))</code>. So, how can I add something like <code>count(type)</code>?</p>

<pre><code>ggplot(dat) +
  geom_bar(aes(type, fill = as.factor(year)), 
           position = "dodge", stat = "identity") + 
  facet_wrap(~day)
</code></pre>