confplot {areaplot}R Documentation

Plot Confidence Bands

Description

Plot confidence bands of lower and upper y values as a filled area, or add polygon to an existing plot.

Usage

confplot(x, ...)

## Default S3 method:
confplot(x, y1 = NULL, y2 = NULL, add = FALSE,
  xlab = NULL, ylab = NULL, border = NA, col = "lightgray", ...)

## S3 method for class 'formula'
confplot(formula, data, subset, na.action = NULL, ...)

Arguments

x

a numeric vector of x values. Alternatively, x can be a matrix or data frame containing x values in the first column and lower and upper y values in the next two columns.

...

further arguments passed to confplot.default, matplot, and polygon.

y1

a numeric vector of lower y values. Alternatively, y1 can be a matrix or data frame containing lower and upper y values in two columns.

y2

a numeric vector of upper y values, if not already supplied in x or y1.

add

whether confidence bands should be added to an existing plot.

xlab

a label for x axis.

ylab

a label for y axis.

border

border color of polygon. The default NA is to omit borders.

col

fill color of polygon.

formula

a formula, such as cbind(y1,y2)~x, specifying x and y values.

data

a data frame (or list) from which the variables in formula should be taken.

subset

an optional vector specifying a subset of observations to be used.

na.action

a function which indicates what should happen when the data contain NA values. The default is to ignore missing values in the given variables.

Value

Data frame of coordinates that were used for plotting.

See Also

polygon is the underlying function used to draw polygons.

areaplot produces a stacked area plot.

areaplot-package gives an overview of the package.

The gplots and plotrix packages provide functions to plot error bars.

Examples

model <- lm(log(dist)~log(speed), cars)
ci95 <- predict(model, data.frame(speed=4:25), interval="confidence")
ci50 <- predict(model, data.frame(speed=4:25), interval="confidence", level=0.5)
x <- log(4:25)
y1 <- ci95[,"lwr"]
y2 <- ci95[,"upr"]
mydata <- data.frame(x, y1, y2)

# Input format
confplot(x, y1, y2)               # vectors
confplot(x, cbind(y1,y2))         # y values in 2 columns
confplot(mydata)                  # data in 3 columns
confplot(cbind(y1,y2)~x, mydata)  # formula

# Overlay
plot(log(dist)~log(speed), cars, type="n")
confplot(x, ci95[,2:3], add=TRUE)
confplot(x, ci50[,2:3], add=TRUE, col="darkgray")
lines(x, ci95[,1])
points(log(dist)~log(speed), cars)


[Package areaplot version 2.1.2 Index]