I have a dataset with this structure:
df<- data.frame (VPD.mean=rnorm(100,mean=2,sd=0.8), treatment=c("ambient","elevated"), variable=rnorm(100,mean=50,sd=10))
df$group <- with(df, as.factor (ifelse (VPD.mean>0 & VPD.mean<=1,"0-1",ifelse (
VPD.mean>1 & VPD.mean<=1.5,"1-1.5",ifelse (
VPD.mean >1.5 & VPD.mean<2, "1.5-2",ifelse (
VPD.mean >=2 & VPD.mean<2.5, "2-2.5",ifelse (
VPD.mean >=2.5 & VPD.mean <3,"2.5-3", ifelse(
VPD.mean >=3,">3", NA)
)))))))
df$group<- factor(df$group,levels=c("0-1","1-1.5","1.5-2" ,"2-2.5","2.5-3",">3"))
I created a boxplot using the groups created after binning VPD.mean, and therefore the x-axis is non-continuous (see graph below):

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:
ggplot(df[!is.na(df$group),], aes(group,variable,fill=treatment)) +
geom_boxplot(outlier.size = 0) + geom_smooth(aes(x=VPD.mean))
What's the solution to plot the geom_smooth from a different x-axis on the same graph? Thanks
