Adding a line in a scatter plot using R

165 views Asked by At
plot(c.6,d.6, xlab="A55 ", ylab="A41", main="H3",cex.main=1)
abline(lm(d.6 ~ c.6),col="red") 

This code works fine, but I want to add two more lines: one where y=x+2 and x=y+2

I would like to add these two lines to visualize those values that fall outside of the lines.

1

There are 1 answers

0
Jota On

You can use the abline function:

abline(2, 1)
abline(-2, 1)

See ?abline:

abline(a = NULL, b = NULL, h = NULL, v = NULL, reg = NULL, coef = NULL, untf = FALSE, ...)

Arguments:

a, b - the intercept and slope, single values.

So, for a specific regression, you could use something like this:

abline(
 coef(lm(d.6 ~ c.6))[1] + 2,
 coef(lm(d.6 ~ c.6))[2]
 )
abline(
 coef(lm(d.6 ~ c.6))[1] - 2,
 coef(lm(d.6 ~ c.6))[2]
 )