I'm using the abline
function in R to draw vertical lines on a plot. Is there a way I can restrict the extent of the line? For example, yf the Y axis goes from 0 to 4, can I plot just the portion from 0 to 2?
The y-axis is an example of a vertical line.
xline( x ) creates a vertical line at one or more x-coordinates in the current axes. For example, xline(2) creates a line at x=2 . xline( x , LineSpec ) specifies the line style, the line color, or both.
The argument main= specifies the overall title for a plot, while xlab= and ylab= specify labels for the x and y axis.
abline() function in R Language is used to add one or more straight lines to a graph. The abline() function can be used to add vertical, horizontal or regression lines to plot. Syntax: abline(a=NULL, b=NULL, h=NULL, v=NULL, …)
Use the segments()
function, e.g.
plot(1:4,1:4,ylim=c(0,4))
abline(v=2)
segments(x0=2,y0=0,x1=2,y1=2,col="red")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With