abline does not draw the regression line well

Dear friends, I am trying to do a simple regression line. When I run abline it doesn't draw well, the line must go through the points, but it does it below

library(zoo)
library(lmtest)
plot(cars$speed,cars$dist)
modelo1=lm(speed~dist, data = cars)
abline(a=coef(modelo1)[1], b=coef(modelo1)[2])

The order of the arguments in your call to plot() do not match the order in lm(). The plot function uses plot(x, y) but lm is lm(y~x). I changed the order in the call to plot.

plot(cars$dist, cars$speed)

modelo1=lm(speed~dist, data = cars)

abline(a=coef(modelo1)[1], b=coef(modelo1)[2])

Created on 2020-04-16 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Ohhh, many, many, thank you FJCC, a very silly mistake on my part.