R: Bar Graph of Calculated Means and CI

bargraph.CI {sciplot} | R Documentation

## Bar Graph of Calculated Means and CI

### Description

Barplot of the mean and standard error (or other summary statistics) of a response variable for one-way or higher experimental designs.

### Usage

    bargraph.CI(x.factor, response, group=NULL, split=FALSE,
        col=NULL, angle=NULL, density=NULL,
        lc=TRUE, uc=TRUE, legend=FALSE, ncol=1,
        leg.lab=NULL, x.leg=NULL, y.leg=NULL, cex.leg=1,
        bty="n", bg="white", space=if(split) c(-1,1),
        err.width=if(length(levels(as.factor(x.factor)))>10) 0 else .1,
        err.col="black", err.lty=1,
        fun = function(x) mean(x, na.rm=TRUE),
        ci.fun= function(x) c(fun(x)-se(x), fun(x)+se(x)),
        ylim=NULL, xpd=FALSE, data=NULL, subset=NULL, ...)

### Arguments

`x.factor` | a factor (required) whose levels will form the x axis.
`response` | a numeric variable giving the response.
`group` | grouping factor (optional) whose levels will form groups of bars for each level of x.factor.
`split` | logical. Should groups of bars be displayed back to back. See details below.
`col` | default color(s) for bars.
`angle` | default angle of shading lines.
`density` | default density of shading lines.
`lc, uc` | logical. Should upper or lower CI be drawn?
`legend` | logical. Should a legend be included?
`ncol` | number of columns to use for legend.
`leg.lab` | legend labels for trace factors.
`x.leg, y.leg` | optional values to over ride the default legend placement.
`cex.leg` | character expansion value for legend labels.
`bty` | line type of bounding box for legend. Defaults to 'none'.
`space` | set spacing for bars.
`err.width` | set width of whiskers for error bars.
`err.col` | color for error bars. Defaults to "black".
`err.lty` | line type for error bars.
`bg` | background color of legend.
`fun` | the function to compute the summary statistic. Should return a single real value. Defaults to mean with NA values removed.
`ci.fun` | the functions to compute the CI. Should return a vector of length 2 defining the lower and upper limits of the CI's. Defaults to the mean +/- 1 standard error, with NA values removed.
`ylim` | range of y axis.
`xpd` | defualts to xpd=FALSE (in contrast to `barplot`) to cut off the range of data plotted.
`data` | an optional data frame.
`subset` | an optional expression indicating the subset of the rows of 'data' that should be used in the plot.
`...` | further graphical parameters. See barplot() for additional options.

### Details

Plots a response as a function of treatment (factor) combinations for one-way and higher designs. This is a "wrapper" function for barplot that adds confidence intervals - `barplot` should be consulted for details. Note that the option "beside=TRUE" from barplot is hardcoded and that the default for value xpd is FALSE. If the option split is specified, the response associated with the second grouping factor will be made negative and displayed back-to-back with the first.

### See Also

`barplot`, `se`

### Examples

    data(ToothGrowth)

    # One way design
    bargraph.CI(x.factor = dose, response = len, data = ToothGrowth)

    # Two-way design with options
    bargraph.CI(dose, len, group = supp, data = ToothGrowth,
                xlab = "Dose", ylab = "Growth", cex.lab = 1.5, x.leg = 1,
                col = "black", angle = 45, cex.names = 1.25,
                density = c(0,20), legend = TRUE)

[Package sciplot version 1.1-1 Index]