I am plotting some data series along with regression lines using this code:
ggplot(dt1.melt, aes(x=lower, y=value, group=variable, colour=variable)) +
geom_point(shape=1) +
geom_smooth(method=lm,
se=FALSE)
However, I need to constrain the regression line to be through the origin for all series - in the same way as abline(lm(Q75~-1+lower,data=dt1))
would achieve on a standard R plot.
Can anyone explain how to do this in ggplot
?
Regression through the Origin means that you purposely drop the intercept from the model. When X=0, Y must = 0. The thing to be careful about in choosing any regression model is that it fit the data well.
Don't force your regression through zero just because you know the true intercept has to be zero. Regression through the origin is when you force the intercept of a regression model to equal zero.
You need to specify this in the formula
argument to geom_smooth
:
... + geom_smooth(method=lm, se=FALSE, formula=y~x-1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With