title: How to add a line to a boxplot using ggplot2
body: <p>I am trying to do box and whisker plots with some forecast data. And want to add observations as a line to the plot. I am producing a sample of the data here so that you can understand how it looks like.</p>
  
  <p><code>$forecasts&lt;- data.frame(f_type=c(rep("A",9),rep("B",9)),Date=c(rep(as.Date("2007-01-31"),3),rep(as.Date("2007-02-28"),3),rep(as.Date("2007-03-31"),3),rep(as.Date("2007-01-31"),3),rep(as.Date("2007-02-28"),3),rep(as.Date("2007-03-31"),3)),value=c(10,50,60,05,90,20,30,46,39,69,82,48,65,99,75,15,49,27))</code></p>
  
  <p><code>$observation&lt;- data.frame(Dt=c(as.Date("2007-01-31"),as.Date("2007-02-28"),as.Date("2007-03-31")),obs=c(30,49,57))</code></p>
  
  <p>With the forecast I can plot the box and whisker plot using ggplot2 like below.</p>
  
  <p><code>$p&lt;- ggplot(data = forecasts, aes(x=as.factor(Date), y=value))
  p&lt;- p + geom_boxplot(aes(fill=f_type))</code></p>
  
  <p>Now I want to add the observations for those dates as a line to this plot. So far, I have tried the following:</p>
  
  <ol>
  <li><p><code>$p&lt;- p + geom_line(data = observation,aes(x=Dt,y=obs))</code> .
  This gives an error saying:</p>
  
  <blockquote>
    <p>Error: Invalid input: date_trans works with objects of class Date only</p>
  </blockquote></li>
  <li><p>with x axis as factor like this:
  <code>$p&lt;- p + geom_line(data = observation,aes(x=as.factor(Dt),y=obs))</code> for which I get the following error:</p>
  
  <blockquote>
    <p>geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?</p>
  </blockquote></li>
  </ol>
  
  <p>Can anyone please suggest how I can accomplish this? Thanks in advance.</p>