Dear sir,
I have a problem about ggplot2.
I want to connect data point with ols result via vertical line, like The code listed below.
Can I transfer ..y.., the value calculated by stat_smooth, to geom_linerange directly?
I tried stat_smooth(...,geom="linerange",mapping(aes(ymin=pmin(myy,..y..),ymax=pmax(myy,..y..)) but it is not the result I want.
Thanks for any help.
library(ggplot2)
df<-data.frame(myx=1:10,myy=c(1:10)*5+2*rnorm(10,0,1))
lm.fit<-lm("myy~myx",data=df)
pred<-predict(lm.fit)
ggplot(df,aes(myx,myy))+geom_point()+geom_smooth(method="lm",se=FALSE)+
geom_linerange(mapping=aes(ymin=pmin(myy,pred),ymax=pmax(myy,pred)))
