[R] re flecting a line

David Epstein David.Epstein at warwick.ac.uk
Wed Sep 10 22:06:04 CEST 2008

Suppose x and y are numeric vectors of the same length.

plot(x,y) #scatterplot
lmObj1 <- lm(y~x) # best fit line
abline(lmObj1) # good
lmObj2 <- lm(x~y) #get best fit but with axes interchanged
abline(lmObj2) # not what I want. I want the correct line, drawn on the same
graph, but with
                    # response and predictor variables interchanged

One way to proceed would be to extract the intercept and slope from lmObj2
and then do the arithmetic to draw the correct line. I'm hoping for a more
streamlined method. Is there one?

View this message in context: http://www.nabble.com/reflecting-a-line-tp19422091p19422091.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list