title: qqnorm and qqline in ggplot2
body: <p>Say have a linear model LM that I want a qq plot of the residuals. Normally I would use the R base graphics:</p>
  
  <pre><code>qqnorm(residuals(LM), ylab="Residuals")
  qqline(residuals(LM))
  </code></pre>
  
  <p>I can figure out how to get the qqnorm part of the plot, but I can't seem to manage the qqline:</p>
  
  <pre><code>ggplot(LM, aes(sample=.resid)) +
      stat_qq()
  </code></pre>
  
  <p>I suspect I'm missing something pretty basic, but it seems like there ought to be an easy way of doing this.</p>
  
  <p><strong>EDIT:</strong> Many thanks for the solution below. I've modified the code (very slightly) to extract the information from the linear model so that the plot works like the convenience plot in the R base graphics package.</p>
  
  <pre><code>ggQQ &lt;- function(LM) # argument: a linear model
  {
      y &lt;- quantile(LM$resid[!is.na(LM$resid)], c(0.25, 0.75))
      x &lt;- qnorm(c(0.25, 0.75))
      slope &lt;- diff(y)/diff(x)
      int &lt;- y[1L] - slope * x[1L]
      p &lt;- ggplot(LM, aes(sample=.resid)) +
          stat_qq(alpha = 0.5) +
          geom_abline(slope = slope, intercept = int, color="blue")
  
      return(p)
  }
  </code></pre>