Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

scatter-plot

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)
like image 202
lara Avatar asked Jul 21 '12 11:07

lara


2 Answers

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.

like image 95
plannapus Avatar answered Sep 18 '22 19:09

plannapus


Use abline, e.g.

abline(-1.331, 2.522)
like image 35
Lars Kotthoff Avatar answered Sep 16 '22 19:09

Lars Kotthoff