title: alignment of two plots using grid.arrange()
body: <p>I have created the following plot using this code: </p>
  
  <pre><code>library(ggplot2)
  library(grid)
  library(gridExtra)
  
  x.test&lt;-c(0,2,4,6,8,12,16,20,24)
  y=c(1,2,3,4,5,6,7,8,9)
  y.test=c(1,2,3,4,5,6,7,8,9)
  
  testdf&lt;-data.frame(x.test,y.test) 
  
  
  heat.time&lt;-x.test
  heat.val&lt;-c(0.2,0.4,0.6,0.8,0.9,0.9,0.9,0.9,0.9)
  testdf2&lt;-data.frame(heat.time,heat.val)
  plot1&lt;-ggplot(testdf,aes(x.test,y.test))+geom_line()+
    scale_x_continuous(limits=c(0,26),breaks=c(0,2,4, 6, 8, 12,16,20,24))
  plot2&lt;-ggplot(testdf2,aes(heat.time,""))+
    geom_tile(data=testdf2,aes(fill=heat.val),height=1, width=0.7)+   
    scale_fill_gradient(low="lightblue",high="blue") +
    scale_x_continuous(limits=c(-1,26),breaks=c(-1,2,4, 6, 8, 12,16,20,24))+
    theme(
      legend.position = "top",
      axis.line=element_blank(),
      axis.text.x=element_blank(),
      axis.text.y=element_blank(),
      axis.ticks=element_blank(),
      axis.title.x=element_blank(),
      axis.title.y=element_blank(),
      panel.background=element_blank(),
      panel.border=element_blank(),
      panel.grid.major=element_blank(),
      panel.grid.minor=element_blank(),
      plot.background=element_blank(),
      plot.margin=unit(c(0,0,-2,0), "cm")
    )
  
  gA &lt;- ggplotGrob(plot2)
  gB &lt;- ggplotGrob(plot1)
  maxWidth = grid::unit.pmax(gA$widths[2:5], gB$widths[2:5])
  gA$widths[2:5] &lt;- as.list(maxWidth)
  gB$widths[2:5] &lt;- as.list(maxWidth)
  grid.arrange(gA, gB, heights=c(0.25,0.75), ncol=1)   
  </code></pre>
  
  <p><img src="https://imgur.com/GHfCmHI.jpg" alt="plot"></p>
  
  <p>However, I can't seem to get the blue bars on the top plot to align with the labeled ticks on the bottom plot even though the two plots have the same horizontal axes scales.  Can anyone help or suggest an alternative method?</p>
  
  <pre><code>sessionInfo()
  R version 3.2.3 (2015-12-10)
  Platform: x86_64-apple-darwin13.4.0 (64-bit)
  Running under: OS X 10.11.6 (El Capitan)
  </code></pre>