1

I need to plot two regresion lines y(x) and x(y) on one plot. Is there any better way than doing this (and if not is it the right way to do it?): 1. counting regression parameters y~x 2. counting regression parameters x~y 3. transforming parameters from 2) 4. plotting two lines with abline

ever graphical package is good for me

askorek
  • 126
  • 1
  • 7
  • Possible duplicate of [add two linear regression lines and two y axis in ggplots](https://stackoverflow.com/questions/51577271/add-two-linear-regression-lines-and-two-y-axis-in-ggplots) – NelsonGon Jan 23 '19 at 13:34
  • 3
    I don't think this is a duplicate of this post, user here want's to plot `x(y)` and `y(x)` lines whereas the user in the other question wants to plot `y(x)` and `z(x)`. – snaut Jan 23 '19 at 13:36

1 Answers1

1

Using the builtin BOD as an example:

plot(demand ~ Time, BOD)
fm1 <- lm(demand ~ Time, BOD)
fm2 <- lm(Time ~ demand, BOD)
abline(fm1)
lines(demand ~ fitted(fm2), BOD, col = "red")

enter image description here

Adela
  • 1,757
  • 19
  • 37
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341