ggplot2 2.1.0 broke my code? Secondary transformed axis now appears incorrectly
<p>Some time ago, I inquired about adding a secondary transformed x-axis in ggplot, and Nate Pope provided the excellent solution described at <a href="https://stackoverflow.com/questions/21026598/ggplot2-adding-secondary-transformed-x-axis-on-top-of-plot/21028809">ggplot2: Adding secondary transformed x-axis on top of plot</a>. </p>

<p>That solution worked great for me, and I returned to it hoping it would work for a new project.  Unfortunately, the solution <strong>doesn't work correctly in the most recent version of ggplot2</strong>.  Now, running the exact same code leads to a <strong>"clipping" of the axis title</strong>, as well as <strong>overlap of the tick marks and labels</strong>.  Here is an example, with the problems highlighted in blue:</p>

<p><a href="https://i.stack.imgur.com/mmGK3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mmGK3.jpg" alt="enter image description here"></a></p>

<p>This example can be reproduced with the following code (this is an exact copy of Nate Pope's code that previously worked marvelously):</p>

<pre><code>library(ggplot2)
library(gtable)
library(grid)

LakeLevels&lt;-data.frame(Day=c(1:365),Elevation=sin(seq(0,2*pi,2*pi/364))*10+100)

## 'base' plot
p1 &lt;- ggplot(data=LakeLevels) + geom_line(aes(x=Elevation,y=Day)) + 
  scale_x_continuous(name="Elevation (m)",limits=c(75,125)) +
  ggtitle("stuff") +
  theme(legend.position="none", plot.title=element_text(hjust=0.94, margin = margin(t = 20, b = -20)))

## plot with "transformed" axis
p2&lt;-ggplot(data=LakeLevels)+geom_line(aes(x=Elevation, y=Day))+
  scale_x_continuous(name="Elevation (ft)", limits=c(75,125),
                     breaks=c(90,101,120),
                     labels=round(c(90,101,120)*3.24084) ## labels convert to feet
  )

## extract gtable
g1 &lt;- ggplot_gtable(ggplot_build(p1))
g2 &lt;- ggplot_gtable(ggplot_build(p2))

## overlap the panel of the 2nd plot on that of the 1st plot
pp &lt;- c(subset(g1$layout, name=="panel", se=t:r))

g &lt;- gtable_add_grob(g1, g2$grobs[[which(g2$layout$name=="panel")]], pp$t, pp$l, pp$b, 
                     pp$l)

g &lt;- gtable_add_grob(g1, g1$grobs[[which(g1$layout$name=="panel")]], pp$t, pp$l, pp$b, pp$l)

## steal axis from second plot and modify
ia &lt;- which(g2$layout$name == "axis-b")
ga &lt;- g2$grobs[[ia]]
ax &lt;- ga$children[[2]]

## switch position of ticks and labels
ax$heights &lt;- rev(ax$heights)
ax$grobs &lt;- rev(ax$grobs)
ax$grobs[[2]]$y &lt;- ax$grobs[[2]]$y - unit(1, "npc") + unit(0.15, "cm")

## modify existing row to be tall enough for axis
g$heights[[2]] &lt;- g$heights[g2$layout[ia,]$t]

## add new axis
g &lt;- gtable_add_grob(g, ax, 2, 4, 2, 4)

## add new row for upper axis label
g &lt;- gtable_add_rows(g, g2$heights[1], 1)
g &lt;- gtable_add_grob(g, g2$grob[[6]], 2, 4, 2, 4)

# draw it
grid.draw(g)
</code></pre>

<p>Running the above code leads to two critical problems, which I am trying to resolve:</p>

<p><strong>1)</strong> How to adjust the x-axis added to the top of the plot to fix the "clipping" and overlap issues?</p>

<p><strong>2)</strong> How to include the <code>ggtitle("stuff")</code> added to the first plot <code>p1</code> in the final plot?</p>

<p>I've been trying to resolve these problems all afternoon, but cannot seem to solve them.  Any help is much appreciated.  Thanks!</p>