title: looping and subsetting in ggplot
body: <p>I'm having difficulties subsetting data within a loop to create multiple ggplots. The objective is to create a plot for each unique value of id.
  The problem I believe is in fill = reason which I believe needs subsetting too.</p>
  
  <pre><code>## Calendar plot loop
  id.calendar &lt;- function(daily, na.rm = TRUE, ...){
  
  myid &lt;- unique(daily$id)
  
  for (i in seq_along(myid)) { 
  
  calendar &lt;-
  ggplot(subset(dat, dat$id==myid[i]),
         aes(monthweek, weekdayf, fill = reason)) +
    geom_tile(colour = "grey80") +
    facet_grid(year~monthf)
  
  print(calendar)
  }
  }
  
  Error: Insufficient values in manual scale. 9 needed but only 6 provided. 
  </code></pre>
  
  <p>dat$id is a string (though it could be converted to numeric). I read somewhere in this forum that subsetting is best done outside of ggplot.  Regardless, I need the loop to be fast.</p>