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

r, scatter-plot

Solution

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.

Problem

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) ```

Original source