title: How can I overlay timeseries models for exponential decay into ggplot2 graphics?
body: <p>I'm trying to plot an exponential decay line (with error bars) onto a scatterplot in ggplot of price information over time.  I currently have this:</p>
  
  <pre><code>f2 &lt;- ggplot(data, aes(x=date, y=cost) ) +
      geom_point(aes(y = cost), colour="red", size=2) +
      geom_smooth(se=T, method="lm", formula=y~x) +
  #   geom_smooth(se=T) +
      theme_bw() +
      xlab("Time") + 
      scale_y_log10("Price over time") +
      opts(title="The Falling Price over time")
  print(f2)
  </code></pre>
  
  <p>The key line is in the geom_smooth command, of <code>formula=y~x</code>  Although this looks like a linear model, ggplot seems to automatically detect my scale_y_log10 and log it.</p>
  
  <p>Now, my issue here is that date is a date data type.  I think I need to convert it to seconds since t=0 to be able to apply an exponential decay model of the form <code>y = Ae^-(bx)</code>.    </p>
  
  <p>I believe this because when I tried things like y = exp(x), I get a message that I think(?) is telling me I can't take exponents of dates.  It reads: </p>
  
  <p><code>Error in lm.wfit(x, y, w, offset = offset, singular.ok = singular.ok,  : 
    NA/NaN/Inf in foreign function call (arg 1)
  </code></p>
  
  <p>However, <code>log(y) = x</code> works correctly.  (y is a numeric data type, x is a date.)</p>
  
  <p>Is there a convenient way to fit exponential growth/decay time series models within ggplot plots in the geom_smooth(formula=formula) function call?</p>