segments(x1, y1, x2=x1, y2=y1, ..., subset, zero=T) arrows(x1, y1, x2=x1, y2=y1, size=.2, open=F, rel=F, ..., subset)
(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.
rel is
TRUE.
If
rel is
FALSE,
size is arrowhead width in inches.
TRUE the arrowhead is "v" shaped, if
FALSE
it is triangular.
TRUE then arrowheads are sized relative to the length of the
arrow.
x1,
y1,
x2, and
y2 to use.
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).
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.
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)
}