Plot Disconnected Line Segments or Arrows

DESCRIPTION:

Adds line segments or arrows to the current plot.

USAGE:

segments(x1, y1, x2=x1, y2=y1, ..., subset, zero=T) 
arrows(x1, y1, x2=x1, y2=y1, size=.2, open=F, rel=F, ..., subset) 

REQUIRED ARGUMENTS:

x1,y1,
x2,y2
coordinates of the end-points of the segments or arrows. Lines will be drawn from (x1[i],y1[i]) to (x2[i],y2[i]).

x2 and y2 may be omitted, in which case they default to x1 and y1, for vertical or horizontal lines, respectively.

Missing values (NA) are allowed. Any segments with any NAs as end-points will not be drawn.

OPTIONAL ARGUMENTS:

size
width of the arrowhead as a fraction of the length of the arrow if rel is TRUE. If rel is FALSE, size is arrowhead width in inches.
open
logical, if TRUE the arrowhead is "v" shaped, if FALSE it is triangular.
rel
logical, if TRUE then arrowheads are sized relative to the length of the arrow.
...
Graphical parameters may also be supplied as arguments to this function (see ).
subset
subscript expression used to select a subset of x1, y1, x2, and y2 to use.
zero
logical, if FALSE then zero-length segments are not drawn. If TRUE then zero-length segments are drawn, typically appearing as a single pixel (except on some graphics devices no point appears if graphics parameters such as lwd or lty are supplied).

SIDE EFFECTS:

Arrows or line segments are added to the current plot.

DETAILS:

Adds line segments or arrows to the current plot from coordinates x1,y1 to coordinates x2,y2. End points specified as NA do not have the arrows or line segments printed.

SEE ALSO:

draws connected line segments, is used for horizontal, vertical, or slope-intercept lines.

EXAMPLES:

x <- 1:5 
y <- c(5,3,2,4,1) 
plot(x,y) 

# draw arrows from 'i'th to 'i+1'st points 
s <- seq(length(x)-1)  # sequence one shorter than x 
arrows(x[s], y[s], x[s+1], y[s+1]) 
 
# horizontal and vertical segments, and subset 
segments(x, y, x+.5, col=2, subset=1:3) 
segments(x, y, y2 = y-.5, col=3, subset=1:3) 
 
# a function to make plots with error bars 
errorbar <- function(x, y, plusmin) 
{ 
        plot(x, y, ylim = c(min(y - plusmin), max(y + plusmin))) 
        segments(x, y + plusmin, y2 = y - plusmin) 
}