title: Custom lm formula in geom_smooth
body: <p>I'm working with faceted plots, and adding lines using the <code>lm</code> method in <code>geom_smooth()</code></p>
  
  <pre><code>d&lt;-data.frame(n=c(100, 80, 60, 55, 50, 102, 78, 61, 42, 18),
                year=rep(2000:2004, 2), 
                cat=rep(c("a", "b"), each=5))
  
  ggplot(d, aes(year, n, group=cat))+geom_line()+geom_point()+
    facet_wrap(~cat, ncol=1)+
    geom_smooth(method="lm")
  </code></pre>
  
  <p>I would like to set up a function to apply a polynomial where appropriate. I've worked up a function:</p>
  
  <pre><code>lm.mod&lt;-function(df){
    m1&lt;-lm(n~year, data=df)
    m2&lt;-lm(n~year+I(year^2), data=df)
    ifelse(AIC(m1)&lt;AIC(m2), "y~x", "y~poly(x, 2)")
  }
  </code></pre>
  
  <p>But I'm having trouble applying it. Any ideas, or better ways to approach this?</p>