lara
lara

Reputation: 503

How do I draw a straight line on plot using R?

I would like to draw a straight line on plot using the following linear equation.

y = 2.522x-1.331

I used the following code to get a scatterplot.

data=read.csv("C://book.csv")
plot(data$x,data$y)

Upvotes: 5

Views: 9118

Answers (2)

plannapus
plannapus

Reputation: 18759

You need to use function abline:

abline(a=-1.331, b=2.522)

Argument a is the intercept and argument b the slope. See ?abline for more details.

Upvotes: 6

Lars Kotthoff
Lars Kotthoff

Reputation: 109272

Use abline, e.g.

abline(-1.331, 2.522)

Upvotes: 2

Related Questions