View source: R/np_plotting_functions.R
errorBars | R Documentation |
Draws error bars with an optional cap at one end
errorBars(
x,
capType = c("none", "bar", "ball"),
capSize = NULL,
side = FALSE,
col = "black",
lType = 1,
width = 1
)
x |
named list or data frame; |
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; |
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. |
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.