title: Plotting year-month accumulative data with missing values
body: <p>I have a data frame with date and count columns. I need to create a bar chart with the x axis displaying the year and month and the y axis displaying the sum of the corresponding rows that fall into the appropriate period.</p>
  
  <pre><code>data &lt;- data.frame(Date = as.Date(c("01/01/2014","02/01/2014","03/03/2014","07/08/2014","08/08/2014","09/08/2014","10/10/2014"),  "%d/%m/%Y"))
  
  x &lt;- as.Date(data$Date)
  y &lt;- sample(10, length(x))
  tmp &lt;- data.frame(dt = format(x, "%Y-%m"), cnt = y, stringsAsFactors = FALSE)
  
  # # Pre-Allocate the table
  # minYr = min(as.numeric(strftime(data$Date, "%Y")))
  # maxYr = min(as.numeric(strftime(data$Date, "%Y")))
  # # The table will contain the number of months in a year.
  # n &lt;- (maxYr - minYr + 1) * 12
  # dt &lt;- character(n)
  # cnt &lt;- numeric(n)
  # for (i in minYr:maxYr) {
  #     for (j in c("01","02","03","04","05","06","07","08","09","10","11","12")) {
  #         lev &lt;- (i - minYr) * 12 + as.numeric(j)
  #         dt[lev] &lt;- paste0(as.character(i),"-",j,"-01")
  #         cnt[lev] &lt;- 0
  #     }
  # }
  # dt = as.Date(dt, format="%Y-%m-%d")
  # tmp &lt;- data.frame(dt = format(dt, "%Y-%m"), cnt, stringsAsFactors = FALSE)
  # tmp &lt;- rbind(tmp, data.frame(dt = format(x, "%Y-%m"), cnt = y, stringsAsFactors = FALSE))
  # 
  
  tmp2 &lt;- aggregate(cnt ~ dt, tmp, sum)
  
  g &lt;- ggplot(tmp2, (aes(x = dt, y = cnt)))
  g + geom_bar(stat="identity")
  </code></pre>
  
  <p>The code above plots the data but if there as no transactions for a particular month these will not show. I want the chart to show missing months with a value of zero.</p>
  
  <p>The remarked chunk of code preallocates each month within the period with zeroes and gives me the desired answer but I was wondering whether I can avoid it by tapping into built in ggplot functionality.</p>