[S] panel.barchart.superpose

Greg Tucker-Kellogg (GTuckerKellogg@genetics.com)
Wed, 27 May 1998 17:51:32 -0500


As I mentioned in a previous posting, I've been unable to use
a 'groups' argument in barchart(), even though it is supposed
to take one. (Using it gives an error in 'polygon()' under S-Plus
4.0r3). I'd like to combine the functionality of
panel.superpose with that of panel.barchart, so I wrote a
panel.barchart.superpose function mostly cribbed from the other two
functions.

The objective is to have a barchart where the bars are filled with
a color depending on a group membership, but I haven't been
able to get it to work. I get coloring that doesn't correspond
to my groups. Here's the function; any help is appreciated.

panel.barchart.superpose <- function(x, y, groups, ...)
{
ok <- !is.na(x) & !is.na(y)
x <- x[ok]
y <- y[ok]
y1 <- y - 1/3
y2 <- y + 1/3
n <- length(y)
xmin <- rep(par("usr")[1], n)
NAs <- rep(NA, n)
groups <- as.numeric(as.factor(groups[ok]))
max.groups <- max(groups)
if (is.null(col)) {
col <- rep(trellis.par.get('superpose.symbol')$col,
length=max.groups)
} else {
col <- rep(col,length=max.groups)
}
N <- seq(along=groups)
for (i in sort(unique(groups))) {
j <- N[groups == i]
polygon(c(rbind(xmin[j], x[j], x[j], xmin[j],NAs[j])),
c(rbind(y1[j], y1[j], y2[j], y2[j], NAs[j])),
col = col[i], border = 1)
}
}

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news