Kumar Jyotirmoy
Kumar Jyotirmoy

Reputation: 11

abline() function not working in R 3.2.0

While using

attach(mtcars)
plot(wt,mpg)

till here it's working fine but when I am trying to add a line to the graph by the below code :

abline(lm (mpg~ wt))

I am getting an error :

Error in x * x : non-numeric argument to binary operator.

Upvotes: 1

Views: 11534

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368201

First off, don't do attach().

Second, you cannot do abline() unless a plot() has come first.

So try this:

plot(mpg ~ wt, data=mtcars)
abline(lm(mpg ~ wt, data=mtcars))

which produces the graph below. enter image description here

Upvotes: 6

Related Questions