title: X-axis labels on uneven facet_wrap rows
body: <p>Currently, I am trying to plot a dataset where there the number of facets is odd, leaving an incomplete final row in the plot. Ideally, I would like x-axis labels below each of the incomplete final row and the row above, where the bottom row is empty.</p>
  
  <p>I have reviewed <a href="https://stackoverflow.com/a/13316126/344016">this question and answer</a>, which appears to do exactly what I want. However, it appears that since this answer was last updated, something has changed in ggplot or gridExtra that breaks the solution when trying to save using <code>ggsave</code>. Instead of creating a valid file, the code prints the structure of the <code>TableGrob</code> to the console (included further down) and producing a corrupt 4KB PDF file (cannot be opened on OS X by QuickLook, Preview or Adobe Reader).</p>
  
  <p>The code I have attempted to use is as follows, which I believe matches that in the original linked answer: </p>
  
  <pre><code>library(ggplot2)
  library(grid)
  
  facetAdjust &lt;- function(x, pos = c("up", "down"))
  {
    pos &lt;- match.arg(pos)
    p &lt;- ggplot_build(x)
    gtable &lt;- ggplot_gtable(p); dev.off()
    dims &lt;- apply(p$panel$layout[2:3], 2, max)
    nrow &lt;- dims[1]
    ncol &lt;- dims[2]
    panels &lt;- sum(grepl("panel", names(gtable$grobs)))
    space &lt;- ncol * nrow
    n &lt;- space - panels
    if(panels != space){
      idx &lt;- (space - ncol - n + 1):(space - ncol)
      gtable$grobs[paste0("axis_b",idx)] &lt;- list(gtable$grobs[[paste0("axis_b",panels)]])
      if(pos == "down"){
        rows &lt;- grep(paste0("axis_b\\-[", idx[1], "-", idx[n], "]"), 
          gtable$layout$name)
        lastAxis &lt;- grep(paste0("axis_b\\-", panels), gtable$layout$name)
        gtable$layout[rows, c("t","b")] &lt;- gtable$layout[lastAxis, c("t")]
      }
    }
    class(gtable) &lt;- c("facetAdjust", "gtable", "ggplot"); gtable
  }
  
  d &lt;- ggplot(diamonds, aes(carat, price, fill = ..density..)) +
  xlim(0, 2) + stat_binhex(na.rm = TRUE) + theme(aspect.ratio = 1) + 
  facet_wrap(~ color)
  
  d &lt;- facetAdjust(d)
  ggsave("test.pdf",d)
  </code></pre>
  
  <p>When run, this produces the following console output:</p>
  
  <pre><code>Saving 7 x 7 in image
  TableGrob (16 x 13) "layout": 33 grobs
      z         cells       name                                    grob
  1   0 ( 1-16, 1-13) background          rect[plot.background.rect.239]
  2   1 ( 4- 4, 4- 4)    panel-1                 gTree[panel-1.gTree.53]
  ...(shortened)...
  32 31 ( 4-12,12-12)  guide-box                       gtable[guide-box]
  33 32 ( 2- 2, 4-10)      title               text[plot.title.text.237]
  </code></pre>
  
  <p>...and also produces a 4KB PDF file that cannot be opened by QuickLook, Preview or Adobe Reader.</p>
  
  <p>I have reviewed the facetAdjust function as best I can, but am not experienced enough to determine what the problem is. Does anyone have any suggestions on how to fix this problem?</p>