geom_errorbar

geom_errorbar(mapping=NULL, data=NULL, stat="identity", position="identity", ...)

Error bars

This page describes geom_errorbar, see layer and qplot for how to create a complete plot from individual components.

What do you think of the documentation? Please let me know by filling out this short online survey.

Aesthetics

The following aesthetics can be used with geom_errorbar. Aesthetics are mapped to variables in the data with the aes function: geom_errorbar(aes(x = var)). Note that you do not need quotes around the variable name.

Scales control how the variable is mapped to the aesthetic and are listed after each aesthetic.

Aesthetic Default Related scales
xrequiredcontinuous, date, datetime, discrete
yminrequired
ymaxrequired
colourblackbrewer, gradient, gradient2, gradientn, grey, hue, identity, manual
size0.5identity, manual, size
linetype1identity, linetype, manual
width0.5
alpha1

Layers are divided into groups by the group aesthetic. By default this is set to the interaction of all categorical variables present in the plot.

Parameters

Parameters control the appearance of the geom. In addition to the parameters listed below (if any), any aesthetic can be used as a parameter, in which case it will override any aesthetic mapping.

Returns

This function returns a layer object.

See also

Examples

> # Create a simple example dataset 
> df <- data.frame( 
+   trt = factor(c(1, 1, 2, 2)), 
+   resp = c(1, 5, 3, 4), 
+   group = factor(c(1, 2, 1, 2)), 
+   se = c(0.1, 0.3, 0.3, 0.2) 
+ ) 
> df2 <- df[c(1,3),] 
>  
> # Define the top and bottom of the errorbars 
> limits <- aes(ymax = resp + se, ymin=resp - se) 
>  
> p <- ggplot(df, aes(fill=group, y=resp, x=trt)) 
> p + geom_bar(position="dodge", stat="identity") 
  
>  
> # Because the bars and errorbars have different widths 
> # we need to specify how wide the objects we are dodging are 
> dodge <- position_dodge(width=0.9) 
> p + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25) 
  
>  
> p <- ggplot(df2, aes(fill=group, y=resp, x=trt)) 
> p + geom_bar(position=dodge) 
  
> p + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25) 
  
>  
> p <- ggplot(df, aes(colour=group, y=resp, x=trt)) 
> p + geom_point() + geom_errorbar(limits, width=0.2) 
  
> p + geom_pointrange(limits) 
  
> p + geom_crossbar(limits, width=0.2) 
  
>  
> # If we want to draw lines, we need to manually set the 
> # groups which define the lines - here the groups in the 
> # original dataframe 
> p + geom_line(aes(group=group)) + geom_errorbar(limits, width=0.2) 
  

What do you think of the documentation? Please let me know by filling out this short online survey.