Reputation: 11
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
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.
Upvotes: 6