title: How to deal with vertical asymptotes in ggplot2
body: <p>Consider three simple mathematical functions :</p>
  
  <pre><code>f1 &lt;- function(x) 1/x
  f2 &lt;- function(x) tan(x)
  f3 &lt;- function(x) 1 / sin(x)
  </code></pre>
  
  <p>There exist certain vertical asymptotes respectively, i.e. f(x) almost gets infinity when x approaches some values. I plot these three functions by <code>ggplot2::stat_function()</code> :</p>
  
  <pre><code># x is between -5 to 5
  ggplot(data.frame(x = c(-5, 5)), aes(x)) + 
    stat_function(fun = f1, n = 1000) +
    coord_cartesian(ylim = c(-50, 50))
  
  # x is between -2*pi to 2*pi
  ggplot(data.frame(x = c(-2*pi, 2*pi)), aes(x)) + 
    stat_function(fun = f2, n = 1000) +
    coord_cartesian(ylim = c(-50, 50))
  
  # x is between -2*pi to 2*pi
  ggplot(data.frame(x = c(-2*pi, 2*pi)), aes(x)) + 
    stat_function(fun = f3, n = 1000) +
    coord_cartesian(ylim = c(-50, 50))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/J9kqr.png" rel="noreferrer"><img src="https://i.stack.imgur.com/J9kqr.png" alt="enter image description here"></a></p>
  
  <p>The asymptotes appear respectively at :</p>
  
  <pre><code>x1 &lt;- 0
  x2 &lt;- c(-3/2*pi, -1/2*pi, 1/2*pi, 3/2*pi)
  x3 &lt;- c(-pi, 0, pi)
  </code></pre>
  
  <p>Actually, these lines do not exist, but <code>ggplot</code> makes them visible. I attempted to use <code>geom_vline()</code> to cover them, namely :</p>
  
  <pre><code>+ geom_vline(xintercept = x1, color = "white")
  + geom_vline(xintercept = x2, color = "white")
  + geom_vline(xintercept = x3, color = "white")
  </code></pre>
  
  <p>The outputs seem rough and indistinct black marks can be seen. Are there any methods which are much robuster ?</p>
  
  <p><a href="https://i.stack.imgur.com/t0JPQ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/t0JPQ.png" alt="enter image description here"></a></p>