# [R] Plotting means and confidence intervals by group factor using lattice graphics?

From: Sander Oom <slist_at_oomvanlieshout.net>
Date: Thu 05 May 2005 - 01:30:04 EST

# Example with confidence intervals and grid hh <- t(VADeaths)[, 5:1]
mybarcol <- "gray20"
ci.l <- hh * 0.85
ci.u <- hh * 1.15
mp <- barplot2(hh, beside = TRUE,

```         col = c("lightblue", "mistyrose",
"lightcyan", "lavender"),
legend = colnames(VADeaths), ylim = c(0, 100),
main = "Death Rates in Virginia", font.main = 4,
sub = "Faked 95 percent error bars", col.sub = mybarcol,
cex.names = 1.5, plot.ci = TRUE, ci.l = ci.l, ci.u = ci.u,
plot.grid = TRUE)
mtext(side = 1, at = colMeans(mp), line = -2,
text = paste("Mean", formatC(colMeans(hh))), col = "red")
```
box()

Or like this:

data(state)
plotmeans(state.area ~ state.region)

Both plotmeans and barplot2 give interesting options such as printing of nobs, among other things. In case of a barplot, there should be an option to plot the confidence intervals in one direction only (up) as to avoid interference with any black and white shading. The plotMeans function provides a useful option error.bars ("se", "sd", "conf.int", "none").

The following test data is still useful:

tmp <- expand.grid(geology = c("Sand","Clay","Silt","Rock"),

species =
c("ArisDiff","BracSera","CynDact","ElioMuti","EragCurS","EragPseu"),

dist = seq(1,9,1) )
tmp\$height <- rnorm(216)

For instance plotting height versus dist by geology.

Any help very welcome!

Cheers,

Sander.

PS Of course the resulting graph will go to the R graph gallery!

```--
--------------------------------------------
Dr. Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work)      +27 (0)11 717 64 04
Tel (home)      +27 (0)18 297 44 51
Fax             +27 (0)18 299 24 64
Email   sander@oomvanlieshout.net
Web     www.oomvanlieshout.net/sander

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help