Web EndMemo

R Draw Lines

abline() function adds a line to plot. It's expression is:

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

a,b:Intercept and slope
h:for horizontal line
v:for vertical line

First let's make a plot:
>x <- c(1.2,3.4,1.3,-2.1,5.6,2.3,3.2,2.4,2.1,1.8,1.7,2.2)
>y <- c(2.4,5.7,2.0,-3,13,5,6.2,4.8,4.2,3.5,3.7,5.2)
>x2 <- c(4.1,1.1,-2.3,-0.2,-1.2,2.3)
>y2 <- c(2.3,4.2,1.2,2.1,-2,4.3)

Let's add a red horizontal line at y=4 to the plot:

Let's add a green vertical line at x=0 to the plot:

Let's add a blue line with intercept 2 and slope 2 to the plot:

lty= and lwd= control the line type and line width. There are 6 line types:

The line width can be a >0 number, for example, lwd from 1 - 8 as follows: