geom_errorbargeom_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.
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 |
|---|---|---|
| x | required | continuous, date, datetime, discrete |
| ymin | required | |
| ymax | required | |
| colour | black | brewer, gradient, gradient2, gradientn, grey, hue, identity, manual |
| size | 0.5 | identity, manual, size |
| linetype | 1 | identity, linetype, manual |
| width | 0.5 | |
| alpha | 1 |
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 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.
This function returns a layer object.
> # 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.