errorBars: Draw Error Bars

Description Usage Arguments Examples

View source: R/utility_functions.R

Description

Adds error bars to an already existing plot.

Usage

1
errorBars(pos, limits = NULL, lb = NULL, ub = NULL, arrow = T, flip = F, ...)

Arguments

pos

A single value or a vector of N values, indicating the position(s) at which an error bar should be drawn.

limits

A vector of 2 values or a 2 x N matrix giving the lower and upper limits, respectively, of the error bars.

lb

A vector of N values with the lower limits for the error bars.

ub

A vector of N values with the upper limits for the error bars.

arrow

Logical; if TRUE, arrows are drawn at each position, otherwise a call is made to polygon to create a filled-in segment representing the connected error bars.

flip

Logical; If TRUE, bars are drawn horizontally instead of vertically. In this case pos denotes the position(s) on the y-axis. Otherwise, pos denotes the position(s) on the x-axis.

...

Additional plotting parameters for the arrows function or, if arrow is FALSE, polygon.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Example of 95% versus 68% intervals for standard normal
plot( c(0,1),c(-6,6),type='n',xaxt='n',xlab=' ',ylab='z-scores' )
pos = c(.25,.75)
limits = cbind( qnorm( c(.025,.975) ), qnorm( c(.16,.84) ) )
errorBars( pos, limits, length = .05, lwd = 2 )
text( pos, limits[2,], c("95%","68%"), pos = 3 )
abline(h=0)

# Example of connected error bars
plot( c(0,1),c(0,1),type='n',xlab=' ',ylab=' ' )
errorBars( c(.2,.8),lb=c(.2,.2),ub=c(.8,.8),arrow=F,col='grey')

rettopnivek/utilityf documentation built on March 1, 2021, 7:05 p.m.