[R] barchart (lattice) with text labels
Mark and Heather Lyman
lymanmh at xmission.com
Sat Feb 24 09:22:27 CET 2007
I would like to place the value for each bar in barchart (lattice) at
the top of each bar. Something like the following code produces.
library(lattice)
mypanelfunc <- function(x, y, ...)
{
panel.barchart(x, y, ...)
panel.text(x, y, labels=as.character(round(x,2)), ...)
}
myprepanelfunc <- function(x, y, ...) list(xlim=c(0, max(x)+.1))
mydata <- expand.grid(a=factor(1:5), b=factor(1:3), c=factor(1:2))
mydata$x <- runif(nrow(mydata))
barchart(a~x|b, mydata, groups=c, panel=mypanelfunc,
prepanel=myprepanelfunc, adj=c(-0.1,0.5))
However, I cannot figure out how to shift the values to correspond with
their respective grouped bar. Has anyone done this type of thing? Thanks.
Mark Lyman
More information about the R-help
mailing list