Plot Pointwise Error Bars

DESCRIPTION:
Plot pointwise error bars given their upper and lower limits .

USAGE:
error.bar(x, y = NULL, lower, upper, incr = T, add = F, bar.ends = T,
          gap = T, horizontal=F)

REQUIRED ARGUMENTS:
x,y:
coordinates of points. The coordinates can be given by two arguments that are vectors or by a single vector x. If a single numeric x is given, time(x) is plotted on the x-axis and x on the y-axis. Missing values (NAs) are allowed. Any points containing missing values will be omitted from the plot.
lower:
pointwise lower limits of the error bar. This may be a single number or a vector of the same length as x and y. If incr = TRUE, then lower is expected to contain the lower half width of the error bar. If incr = FALSE, then lower contains the coordinates of the lower limit in terms of x or y according to whether we want the bars to be horizontal or not.

OPTIONAL ARGUMENTS:
upper:
vector of the same length as x and y representing the upper limit of pointwise error bars. As with lower this can be a single number or a vector, and if incr = TRUE, it should contain increments and not actual coordinates. If missing, then upper is drawn symmetrical to lower around y (or x).
incr:
logical variable. If incr = TRUE, then the value of lower is considered to represent half the widths of the error bar (increments). This affects both the value of lower and upper the same way, that is, they both are assumed to contain increments or coordinates.
add:
logical flag. Should the error bar be added to the actual plot? If add = TRUE, the user should make sure that the plot parameter ylim (or xlim) is used to provide enough room in the plot for the error bars; otherwise, "Lines out of bounds" warnings will be generated.
gap:
logical flag. Should a gap be left around the point to emphasize its location?
bar.ends:
logical flag. Do we want flat bars at the endpoints? These are provided for aesthetical reasons.
horizontal:
logical flag. Should the error bars be oriented horizontally?

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


SIDE EFFECTS:
Creates a plot of y versus x with pointwise error bars.

SEE ALSO:
plot , segments , pointwise .

EXAMPLES:
# Approximate 95% confidence band for Normally distributed y

error.bar(y, lower = qnorm(.975) * std.err.y)

# Using error.bar in conjunction with predict methods

attach(gas) gas.m <- loess(NOx ~ E, data = gas, span = 2/3) E.new <- seq(min(E), max(E), length = 7) gas.se <- predict(gas.m, newdata = E.new, se.fit = TRUE) gas.bars <- pointwise(gas.se) error.bar(E.new, gas.bars$fit, gas.bars$lower, gas.bars$upper)

# Using error.bar to plot unprocessed data

x <- rep(1:5,c(4,5,6,3,8)) # Group memberships y <- c(12.3,14.6,12.7,13.8,23.1,34.2,32.3,21.5,26.4,56.4,45.7,45.9,50.2, 48.8,47.2,80.2,75.1,77.8,50.3,55.8,54.2,51.4,34.7,54.9,49.8,55.5) tmp.means <- tapply(y, x, mean) tmp.se <- sqrt(tapply(y, x, var)/tapply(y, x, length)) error.bar(unique(x), tmp.means, tmp.se, incr=T)