Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of "xlim" or "ylim" for vertical/horizontal abline?

Tags:

r

graphics

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?

like image 447
Daniel Standage Avatar asked Jul 08 '14 14:07

Daniel Standage


People also ask

Is YXA horizontal or vertical line?

The y-axis is an example of a vertical line.

How to insert a vertical line in MATLAB?

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.

What is the purpose of using XLAB and YLAB argument in plot () function?

The argument main= specifies the overall title for a plot, while xlab= and ylab= specify labels for the x and y axis.

What is the Abline?

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, …)


1 Answers

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")
like image 184
Ben Bolker Avatar answered Sep 20 '22 01:09

Ben Bolker