How to add a straight line to a plot in R starting from bottom left and ending at top right?


The abline function can give us a straight line from intercept 0 with slope 1 in an existing plot. We would need to pass the coefficients inside the function as abline(coef = c(0,1)). Therefore, we can use this function to add a line starting from bottom left and ending at top right. This is also called diagonal line because it joins the end points on one side with the opposite of the other side.

Example

> plot(1:10,type="n")
> abline(coef=c(0,1))

Output:

Updated on: 23-Nov-2020

94 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements