title: How to group by month, quarter or year using ggplot2
body: <p>Given the following case:</p>
  
  <pre><code>a &lt;- c(rep("A", 25), rep("B", 25))
  b &lt;- rep(as.Date(c("2007-01-01")) + seq(60,1500,60),2)
  c &lt;- runif(50, 0, 1000)
  d &lt;- data.frame(a,b,c)
  </code></pre>
  
  <p>If I visualize this using ggplot2 I get a nice bar chart</p>
  
  <pre><code>ggplot(data = d, aes(x=b, y=c, fill=a)) + 
  geom_bar(stat = "identity") + 
  scale_x_date(breaks = as.Date(c("2007-01-01", "2008-01-01", "2009-01-01", "2010-01-01", "2011-01-01")), 
  minor_breaks = NULL)
  </code></pre>
  
  <p><img src="https://i.imgur.com/387T3x8.png" alt="1"></p>
  
  <p>Note: One bar represents one observation.</p>
  
  <p>However, I would like to be able to quickly group these observations together and have only 1 bar chart per year or 1 bar chart for every 2 years.</p>
  
  <p>How is it possible to do this using ggplot2?</p>