title: calendar heat map tetris chart
body: <p>So I was reading <a href="https://stackoverflow.com/questions/2076370/most-underused-data-visualization">this post</a> and I fell a little in love with the calendar heat map with Tetris-style month breaks.</p>
  
  <p>However, the <code>ggplot</code> example doesn't implement the Tetris breaks, which are arguably the best part. </p>
  
  <p>So, FTFY, <a href="https://gist.github.com/dvmlls/5f46ad010bea890aaf17" rel="nofollow noreferrer">gist here</a>: </p>
  
  <p><img src="https://i.stack.imgur.com/0cL4l.png" alt="results"></p>
  
  <p>The procedure for this is:</p>
  
  <ol>
  <li>create appropriate Tetris breaks for your data</li>
  <li><code>left_join</code> your data to the Tetris breaks created in (1)</li>
  <li>pump the above through <code>ggplot</code> with some specially crafted <code>geom</code>s </li>
  </ol>
  
  <p>The methodology for (1) is reasonably straightforward, implemented in the <code>calendar_tetris_data(...)</code> function in the <a href="https://gist.github.com/dvmlls/5f46ad010bea890aaf17" rel="nofollow noreferrer">gist</a>, though it would be nice to make it a little more flexible.</p>
  
  <p>My question is mainly around (3): how do I bundle up the 7 <code>geom</code>s necessary to make the breaks into a single procedure or <code>geom</code>?</p>
  
  <p>If I do this:</p>
  
  <pre><code>calendar_tetris_geoms &lt;- function() {
    geom_segment(aes(x=x, xend=x, y=ymin, yend=ymax)) +                    # (a)
      geom_segment(aes(x=xmin, xend=xmax, y=y, yend=y)) +                  # (b)
      geom_segment(aes(x=dec.x, xend=dec.x, y=dec.ymin, yend=dec.ymax)) +  # (c)
      geom_segment(aes(x=nye.xmin, xend=nye.xmax, y=nye.y, yend=nye.y)) +  # (d)
      geom_segment(x=-0.5, xend=51.5, y=7.5, yend=7.5) +                   # put a line along the top
      geom_segment(x=0.5, xend=52.5, y=0.5, yend=0.5) +                    # put a line along the bottom
      geom_text(aes(x=month.x, y=month.y, label=month.l), hjust=0.25)      # (e)
  
  }
  </code></pre>
  
  <p>And then try to add that to my <code>ggplot</code>, it doesn't work:</p>
  
  <pre><code>&gt; ggplot(data) + calendar_tetris_geoms()
  Error in calendar_tetris_geoms() : 
    argument "plot" is missing, with no default
  </code></pre>
  
  <p>I clearly don't understand how this works. How does this work? </p>