0

How can I add a straight line form (5, 5) to infinity to this plot? I use abline but I do not want the line between 5 to 5, just I need after 5 to infinity.

x <- c(1:5); y <- x
plot(x, y, type="l")
abline(v= max(x), col="black", lwd=2, lty=2)
thelatemail
  • 85,757
  • 12
  • 122
  • 177
rose
  • 1,911
  • 7
  • 26
  • 32

1 Answers1

3

You can use segments and par('usr') to extract the existing axis limits. I've used lty=1 to show that it wil extend to the edge of the plotting area

 plot(x,y,type = 'l')
 segments(x0 = max(x), y0 = max(y), y1 = par('usr')[4], lwd=2)

enter image description here

mnel
  • 110,110
  • 27
  • 254
  • 248