How to draw a straight line on a chart using R?

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

y = 2.522x-1.331 

I used the following code to get a scatter plot.

 data=read.csv("C://book.csv") plot(data$x,data$y) 
+4
source share
2 answers

You need to use the abline function:

 abline(a=-1.331, b=2.522) 

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

+5
source

Use abline for example

 abline(-1.331, 2.522) 
+2
source

All Articles