title: modify scale in existing ggplot object without replacing the scale
body: <p>I have a ggplot object. It has an x-axis label that was created by <code>scales_x_continuous()</code>. Without recreating the plot, and without changing any of the other arguments that were passed to <code>scale_x_continuous()</code>, I want to change the x-axis label. How may I do this?</p>
  <p>There are many SO posts about updating ggplot objects after they have been created. But as best I can tell, the solutions in those posts don't apply to this particular situation. To fix ideas, here is a small example:</p>
  <pre><code>library(ggplot2)
  p &lt;- ggplot(mtcars, aes(mpg, wt)) + 
    geom_point() + 
    scale_x_continuous(name = &quot;oldLabel&quot;, limits = c(15, 30))
  </code></pre>
  <p>I want to change the x-axis label from &quot;oldLabel&quot; to &quot;newLabel&quot; without overriding the <code>limits</code> argument. Many seemingly obvious strategies mentioned in other posts don't work in this case:</p>
  <ol>
  <li><p><code>p + scale_x_continuous(name = &quot;newLabel&quot;)</code> changes the label -- but it also changes the limits. I could get around that problem by calling <code>p + scale_x_continuous(name = &quot;newLabel, limits = c(15, 30)&quot;)</code>. But in practice, the ggplot objects that I use may be created with many arguments to <code>scale_x_continuous()</code>, and I don't want to repeat them all just to override the x-axis label.</p>
  </li>
  <li><p><code>p + xlab(&quot;newLabel&quot;)</code> doesn't replace the label. That is, <code>xlab()</code> seems to have no effect in this case. It would work if the original label had been specified with <code>xlab()</code>, but that isn't the case here.</p>
  </li>
  <li><p><code>update_labels(p, list(x = &quot;new x label&quot;))</code> also doesn't replace the label.</p>
  </li>
  <li><p><code>ggplot_build()</code> also seems to have no effect, at least as I've been using it:</p>
  </li>
  </ol>
  <pre><code>library(gridExtra)
  tmp &lt;- ggplot_build(p)
  tmp$layout$panel_params[[1]]$x$name     &lt;- &quot;newLabel&quot;
  tmp$layout$panel_params[[1]]$x.sec$name &lt;- &quot;newLabel&quot;
  grid.arrange(ggplot_gtable(tmp))
  </code></pre>