title: Plotting regression line on scatter plot using ggplot
body: <p>I have a quadratic regression model. I would like to add the model's 
  fitted regression line to a scatter plot. My preference is to use ggplot2.
  I am able to draw the scatter plot but when I use "stat_smooth()"
  to specify the formula, I get the following warning and the fitted
  line is not drawn on the scatter plot.</p>
  
  <p>Warning messages:
  1: 'newdata' had 80 rows but variables found have 24 rows 
  2: Computation failed in <code>stat_smooth()</code>:
  arguments imply differing number of rows: 80, 24</p>
  
  <p>My code is below. Can someone please guide me what should I do
  differently so that I can get fitted regression line in a scatter
  plot using ggplot.</p>
  
  <p>Code:</p>
  
  <pre><code>library(gamair)
  library(ggplot2)
  data(hubble)
  
  names(hubble)[names(hubble) == "y"] &lt;- c("velocity")
  names(hubble)[names(hubble) == "x"] &lt;- c("distance")
  
  hubble$distance.sqr &lt;- hubble$distance^2
  model2.formula &lt;- hubble$velocity ~ hubble$distance + 
     hubble$distance.sqr - 1
  model2.hbl &lt;- lm(model2.formula, data = hubble)
  summary(model2.hbl)
  
  model2.sp &lt;- ggplot(hubble, aes(x = distance, y = velocity)) +
    geom_point() + labs(title = "Scatter Plot between Distance &amp; Velocity", 
    x = "Distance", y = "Velocity")
  model2.sp + stat_smooth(method = "lm", formula = hubble$velocity ~ 
    hubble$distance + hubble$distance.sqr - 1)
  </code></pre>