Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flexible diagonal line plot in R

How can we plot diagonal across (from bottom-left-hand corner to top right-hand corner), at any given coordinate ranges?

For example

> plot(c(-2,3), c(-1,5), type = "n", xlab="x", ylab="y", asp = 1)

or

> plot(c(0,1000), c(0,334), type = "n", xlab="x", ylab="y", asp = 1)

I tried abline with the following but failed:

> abline(0,1,col="red")
like image 338
neversaint Avatar asked Mar 12 '12 05:03

neversaint


1 Answers

The limits of the current plot area are in par()$usr.

lines( par()$usr[1:2], par()$usr[3:4] )
like image 157
Vincent Zoonekynd Avatar answered Oct 31 '22 21:10

Vincent Zoonekynd