Message-ID: <AANLkTimA-SR7qMSAkpGMR3uAEHbrPH2+7+pzgnmxudxR@mail.gmail.com>
Date: 2011-01-31T22:34:39Z
From: Rajarshi Guha
Subject: arranging pie charts in a matrix layout with row/col labels
Hi, I have a vector of data, that I group based on two factors via
tapply. For each such grouping I would like to plot a pie chart. I
can layout these pie charts in a matrix layout, correpsonding to the
levels of the two factors. But I am getting stuck on how to label the
rows and colums. My current approach looks like this:
x <- data.frame(obs=sample(c('low', 'high'),100, replace=TRUE),
grp1=sample(1:10, 100, replace=TRUE),
grp2=runif(100))
cut.grp1 <- cut(x$grp1, 3)
cut.grp2 <- cut(x$grp2, 3)
par(mfrow=c(3,3))
tapply(x$obs, list(cut.grp1, cut.grp2), function(z) {
pie(table(z), col=c('red', 'green'))
})
One possibility is to add an extra row and column to the layout and
loop over the results of the tapply, adding a text label for the row
and column labels.
Is there a better way to achieve this?
--
Rajarshi Guha
NIH Chemical Genomics Center