title: ggplot - Add regression line on a boxplot with binned (non-continuous) x-axis
body: <p>I have a dataset with this structure:</p>
  
  <pre><code>df&lt;- data.frame (VPD.mean=rnorm(100,mean=2,sd=0.8), treatment=c("ambient","elevated"), variable=rnorm(100,mean=50,sd=10))
  df$group &lt;- with(df, as.factor (ifelse (VPD.mean&gt;0 &amp; VPD.mean&lt;=1,"0-1",ifelse (
    VPD.mean&gt;1 &amp; VPD.mean&lt;=1.5,"1-1.5",ifelse (
      VPD.mean &gt;1.5 &amp; VPD.mean&lt;2, "1.5-2",ifelse (
        VPD.mean &gt;=2 &amp; VPD.mean&lt;2.5, "2-2.5",ifelse (
          VPD.mean &gt;=2.5 &amp; VPD.mean &lt;3,"2.5-3", ifelse(
            VPD.mean &gt;=3,"&gt;3", NA)  
        )))))))
  df$group&lt;- factor(df$group,levels=c("0-1","1-1.5","1.5-2" ,"2-2.5","2.5-3","&gt;3"))
  </code></pre>
  
  <p>I created a boxplot using the groups created after binning VPD.mean, and therefore the x-axis is non-continuous (see graph below):
  <img src="https://i.stack.imgur.com/aNrjt.jpg" alt="enter image description here"></p>
  
  <p>I would also like to add a regression line (smooth), and therefore I would have to use the continuous variable (VPD.mean) instead of the binned one (groups) as x-axis. The result is not nice, because the smooth line doesn't match the x-axis of the graphs. This is the code for the ggplot:</p>
  
  <pre><code>ggplot(df[!is.na(df$group),], aes(group,variable,fill=treatment)) + 
    geom_boxplot(outlier.size = 0) + geom_smooth(aes(x=VPD.mean)) 
  </code></pre>
  
  <p>What's the solution to plot the geom_smooth from a different x-axis on the same graph?
  Thanks</p>