title: Creating a monthly/yearly calendar image with ggplot2
body: <p>I started to make a calendar in Excel, but thought it might be easy to do in R instead. (Note: I'm aware of various heatmap calendar packages but I prefer to use <code>ggplot2</code>.) Ultimately I want to make a calendar that shows 12 months starting from a given date, with each month as a small box showing 4 or 5 weeks on the y-axis (week 1 at the top, week 4 or 5 at the bottom) and the days of the week (starting from Monday) along the x-axis.</p>
  
  <p>I thought this would be a 15-minute job (create data for all months, format a bit using <code>reshape</code> then use <code>facet_wrap</code>) but ran into problems almost immediately as the plot below shows - the days of the month are not in order, although the days of the week seem okay. Ordering data in R is my nemesis; I really should get a handle on this. Anyway, the image below shows what I have so far and the code is below that. This is just a fun project, not urgent, but any help and/or embellishments welcome.</p>
  
  <p><img src="https://i.stack.imgur.com/ZOrY7.png" alt="calendar"></p>
  
  <pre><code>require(ggplot2)
  require(scales)
  require(lubridate)
  
  date.start &lt;- as.Date('2013-09-01')
  date.end &lt;- date.start + months(1)
  
  mydf &lt;- data.frame(mydate = seq(as.Date(date.start),
                         as.Date(date.end) - days(1),
                         by = 'day'))
  
  mydf$month &lt;- month(mydf$mydate)
  mydf$week &lt;- week(mydf$mydate)
  mydf$day &lt;- day(mydf$mydate)
  mydf$dow &lt;- as.factor(format(mydf$mydate, format = "%a"))
  levels(mydf$dow) &lt;- c('Mon','Tue','Wed','Thu','Fri','Sat','Sun')
  
  ggplot(mydf, aes(x = dow, y = as.factor(week))) +
      geom_tile(colour = "black", fill = "white", label = mydf$day) +
      geom_text(label = mydf$day, size = 4, colour = "black") +
      scale_x_discrete(expand = c(0,0)) +
      theme(axis.ticks = element_blank()) +
      theme(axis.title.y = element_blank()) +
      theme(axis.title.x = element_blank()) +
      theme(panel.background = element_rect(fill = "transparent"))+
      theme(legend.position = "none") +
      theme()
  </code></pre>