Hi:
Here's a simple example of how to produce an error bar plot in ggplot2
with the mean as center and quartiles as endpoints of the error bars.
library(ggplot2)
# Fake some data
d <- data.frame(a = rnorm(50), b = rnorm(50, 2), u = rnorm(50, 4, 3),
v = rnorm(50, 5, 5))
# Create a function that returns the first quartile, mean and third quartile
f <- function(x) c(quantile(x, 0.25), mean(x), quantile(x, 0.75))
# Apply it to the columns of d and add the variable names into a data frame
dd <- data.frame(c('a', 'b', 'u', 'v'), t(apply(d, 2, f)))
# rename
names(dd) <- c('x', 'q25', 'm', 'q75')
# Create the scaffolding for a ggplot
g <- ggplot(dd, aes(x = x, y = m, ymin = q25, ymax = q75))
# Add the layers
g + geom_point(size = 3) + geom_errorbar(width = 0.3)
# Horizontal error bars instead
last_plot() + coord_flip()
The size and width can be adjusted to taste and other elements can be added
to the plot. geom_errorbar() requires an x (group), y (center), ymin (lower limit)
and ymax (upper limit). You get to choose the center, upper and lower limits.
HTH,
Dennis