title: ggplot2: line connecting the means of grouped data
body: <p>I'm trying to group one variable of my data by another and then plot a line through the means. It works fine when both variables are numbers. However, I'm having a problem when the grouping variable is a factor. I have a mock up below. </p>
  
  <pre><code>x &lt;- sample(1:3, 40, replace=T)
  y &lt;- rnorm(40)
  
  df1 &lt;- data.frame(x, y)
  qplot(x, y, data=df1) + stat_summary(fun.y=mean, colour="red", geom="line")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/MvrbB.png" alt="alt text"></p>
  
  <p>This is looks great. However if the x variable is a factor I don't get the line. </p>
  
  <pre><code>df2 &lt;- data.frame(x=as.factor(x), y)
  qplot(x, y, data=df2) + stat_summary(fun.y=mean, colour="red", geom="line")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Sanw8.png" alt="alt text"></p>
  
  <p>Is there something I can do to get this line displayed?</p>
  
  <p>Ps. geom="point" works but not geom="line"</p>
  
  <pre><code>qplot(x, y, data=df2) + stat_summary(fun.y=mean, colour="red", geom="point")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/7RoA5.png" alt="alt text"></p>