title: Adjusting a confidence interval in ggplot while maintaining the default plot margin buffers
body: <p>For the sake of data access, let us use the in-built JohnsonJohnson dataset:</p>
  
  <pre><code>dat &lt;- JohnsonJohnson
  df &lt;- data.frame(date = time(dat), Y = as.matrix(dat))
  </code></pre>
  
  <p>Now to plot the time series with a 99 percent confidence interval:</p>
  
  <pre><code>p1 &lt;- ggplot(df, aes(date, Y)) +
          geom_point() +
          geom_smooth(level = 0.99) +
          theme_bw()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/mpzP8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mpzP8.png" alt="enter image description here"></a></p>
  
  <p>This is close to what I want, except that it is nonsensical to have the confidence interval go below zero.</p>
  
  <p>The recommended remedy is to use <code>coord_cartesian()</code> to set the limits of the plotting area like so:</p>
  
  <pre><code>max &lt;- ggplot_build(p1)$panel$ranges[[1]]$y.range[2]
  p2 &lt;- p1 + coord_cartesian(ylim = c(0, max))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/SljQz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SljQz.png" alt="enter image description here"></a></p>
  
  <p>However, I do not want the minimum value of the plot margins to be where y = 0. I like having the default buffer of space separating the most extreme values from the edges of the plot margins on all four sides. You can see this in p1 (the plot before adding the <code>coord_cartesian()</code> argument), but only on three sides in p2.</p>
  
  <p>So in short, I'd like to keep the confidence interval flattened where y = 0 (as <code>coord_cartesian()</code> does) without removing any of the underlying data (as <code>scale_y_continuous()</code> would do), but while maintaining the default plot margin buffers that p1 has.</p>
  
  <p>If it is helpful to know, the default plotting range is 10% greater than the range of plotted objects (i.e. the maximum range of all points and confidence intervals) for each dimension.</p>