# [R] Regression lines

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Jan 12 11:10:21 CET 2007

```
Tom Backer Johnsen wrote:
> My simpleminded understanding of simple regression is that when
> plotting regression lines for x on y and y on x in the same plot, the
> lines should cross each other at the respective means.  But, given the
> R function below, abline (lm(y~x)) works fine, but abline (lm(x~y))
> does not.  Why?

Well, abline() in fact plots a line using the estimated coefficients for
intercept and slope and assumes you have plotted LeftHandSideOfFormula
against RightHandSideOfFormula.
If you did vice versa, abline() does not respect your mistake.

Uwe Ligges

> function () {
> attach (attitude)
> x <- rating
> y <- learning
> detach (attitude)
> plot (x, y)
> abline(v=mean(x))
> abline(h=mean(y))
> abline (lm(y~x))
> abline (lm(x~y))
> }
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help