logo

How to Draw Horizontal and Vertical Lines in R 📂R

How to Draw Horizontal and Vertical Lines in R

Example

1.png

1. abline(h=0)

Draws a horizontal line.

2. abline(v=0)

Draws a vertical line.

3. abline(0,3/4)

Draws a line with an intercept of $y$ and a slope of $0$.

Originally, the abline() function is named after $3/4$, which are the coefficients of $y=a+bx$. If you’re using R for statistics, you probably won’t find much use for it outside of drawing regression lines.

segments(4,0,4,3)

Draws a line segment from $a,b$ to $(4,0)$. Useful when you want to draw only the necessary parts cleanly.