Plot Disconnected Line Segments or Arrows

DESCRIPTION:
Adds line segments or arrows to the current plot.

USAGE:
segments(x1, y1, x2, y2)
arrows(x1, y1, x2, y2, size=.2, open=F, rel=F)

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]).
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, should arrowhead be sized relative to the length of the arrow?

Graphical parameters may also be supplied as arguments to this function (see par).


SIDE EFFECTS:
Arrows or line segments will be added to the current plot.

DETAILS:
Prints line segments or arrows on the current plot from coordinates x1,y1 to coordinates x2,y2. End points specified as NA will not have the arrows or line segments printed.

SEE ALSO:
lines which draws connected line segments, abline .

EXAMPLES:
# draw arrows from ith to i+1st points
s <- seq(length(x)-1)  # sequence one shorter than x
arrows(x[s], y[s], x[s+1], y[s+1])

# 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, x, y - plusmin) }