Learn R Programming

sfsmisc (version 0.9-4)

plotCI: Plot Confidence Intervals / Error Bars

Description

Given a set of x and y values and upper and lower bounds, this function plots the points with error bars. Can be used for confidence interval visualization as well.

Usage

plotCI(x, y = NULL, uiw, liw = uiw, aui = NULL, ali = aui,
       err = "y", xlim = NULL, ylim = NULL, type = "p", log = "",
       sfrac = 0.01, gap = 0, add = FALSE,
       col = par("col"), lwd = par("lwd"), slty = par("lty"),
       scol = col, pt.bg = NA,
       xlab = NULL, ylab = NULL, main = "", axes = TRUE, ...)

Arguments

x
the x coordinates of points in the plot
y
the y coordinates of points in the plot
uiw
the width of the upper portion of the confidence region, or (if liw is missing) the width of both halves of the confidence region
liw
the width of the lower portion of the confidence region (if missing, the function assumes symmetric confidence bounds)
aui
the absolute upper limit of the confidence region
ali
the absolute lower limit of the confidence region
err
character giving the direction of error bars: "x" for horizontal, "y" for vertical ("xy" would be nice but is not implemented yet).
xlim
x limits of the plot
ylim
y limits of the plot
type
point/line type; passed to points
log
character indicating if log scales should be use in x or y; passed to plot.default().
gap
size of gap in error bars around points (default 0)
sfrac
scaling factor for the size of the serifs (end bars) on the confidence bars, in x-axis units
add
logical; if FALSE (default), create a new plot; if TRUE, add error bars to an existing plot.
col
color of points
lwd
line width of error bars
slty
line type of error bars
scol
color of error bars
pt.bg
background color of points (use pch=21, pt.bg=par("bg") to get open points superimposed on error bars).
xlab, ylab
horizontal and vertical axis labels.
main
main title, see plot.default or title.
axes
logical indicating if axes should drawn, see plot.default.
...
any other parameters to be passed through to plot.

Value

  • None.

TO DO

Fixes for logarithmic axes; simultaneous horizontal and vertical error bars. The main problem is figuring how parameters should be specified.

Examples

Run this code
y <- runif(10)
  err <- runif(10)
  plotCI(1:10,y,err)
  plotCI(1:10,y,err,2*err,lwd=2,col="red")
  err.x <- runif(10)
  err.y <- runif(10)
  plotCI(1:10,y,err.y,pt.bg=par("bg"),pch=21)
  plotCI(1:10,y,err.x,pt.bg=par("bg"),pch=21,err="x",add=TRUE)

Run the code above in your browser using DataLab