ggplot ribbon cut off at y limits : <p>I want to use geom_ribbon in ggplot2 to draw shaded confidence ranges. But if one of the lines goes outside the set y limits, the ribbon is cut off without extending to the edge of the plot.</p>

<p>Minimal example</p>

<pre><code>x &lt;- 0:100
y1 &lt;- 10+x
y2 &lt;- 50-x

ggplot() + theme_bw() +
  scale_x_continuous(name = "x", limits = c(0,100)) +
  scale_y_continuous(name = "y", limits = c(-20,100)) +
  geom_ribbon(aes(x=x, ymin=y2-20, ymax=y2+20), alpha=0.2, fill="#009292") +      
  geom_line(aes(x=x , y=y1)) +
  geom_line(aes(x=x , y=y2)) 
</code></pre>

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

<p>What I want is to reproduce the same behaviour as I get with plotting in base R, where the shading extends to the edge</p>

<pre><code>plot(x, y1, type="l", xlim=c(0,100),ylim=c(-20,100))
lines(x,y2)
polygon(c(x,rev(x)), c(y2-20,rev(y2+20)), col="#00929233", border=NA)
</code></pre>

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