errorBars: draw custom error bars

View source: R/np_plotting_functions.R

errorBarsR Documentation

draw custom error bars

Description

Draws error bars with an optional cap at one end

Usage

errorBars(
  x,
  capType = c("none", "bar", "ball"),
  capSize = NULL,
  side = FALSE,
  col = "black",
  lType = 1,
  width = 1
)

Arguments

x

named list or data frame; x$start, x$stop and x$at must all be defined as numeric vectors in a named list or data.frame object. In the case of a data frame, each row returns a single error bar.

capType

character; can be set to 'none', 'bar', 'ball'. If set to 'bar' or ball, a round point or a line segment will be used to cap the end of the error bar.

capSize

numeric; capSize is the distance that the cap extends away from the error bar. Set to NULL to suppress the cap regardless of the capType setting.

side

logical; if set to true, the error bars will be drawn horizontally.

col

color; a vector of line colors.

lType

positive integer; corresponds to lty line type in base R.

width

positive numeric; corresponds to lwd line width setting in base R.

Details

The input data frame x should have columns labels 'at','start',and 'stop' with at determining the x-axis location and start and stop indicating the position of the segment on the y-axis. If side=TRUE then the x and y axises are swapped to support horizontal plotting. Each row of the data frame will produce one bar and an optional cap can be drawn at the 'stop' location.

Examples

data(iris)
library(dplyr)
iData<-iris %>% group_by(Species) %>%
   summarize(Average=mean(Sepal.Length),SD=sd(Sepal.Length))
barplot(iData$Average,ylim=c(0,10),names=levels(iris$Species),ylab="sepal length")
loc<-c(.7,1.9,3.1)
top<-iData$SD*2+iData$Average
bottom<-iData$SD*-2+iData$Average
errorBars(data.frame(at=loc,start=iData$Average,stop=top),capType="ball",capSize=2)
errorBars(data.frame(at=loc,start=iData$Average,stop=bottom),capType="ball",capSize=2)

ZachHunter/NicePlots.R documentation built on Sept. 23, 2023, 4:04 a.m.