Skip to content
Prev 77728 / 398502 Next

annotating an axis in bwplot (lattice)

On 9/20/05, Sebastian Luque <spluque at gmail.com> wrote:
It's not clear to me what you want to do. Do you want the sample size
for the data in that panel, or for all the data? Your current
implementation does the latter, and in a way that wouldn't work if you
actually had a 'data' argument. If the former, then you should have
done


bwplot(grp ~ age | sex, aspect = 0.5, box.ratio = 2,
      panel = function(x, y, ...) {
        panel.bwplot(x, y, nout = 0.01, probs = seq(0.05, 0.45, 0.05))
        nage <- tapply(x, y, length)
        panel.text(rep(0, length(x)), seq(along = x), labels = nage)
      })

in which case data and subset wouldn't be a problem. If you really
want the frequencies for the whole (subsetted) data, you might as well
use something like:

dd <- data.frame(age, sex, grp)

with(subset(dd, age > 20),
     bwplot(grp ~ age | sex, aspect = 0.5, box.ratio = 2,
	    ylim = {
	      tg <- table(grp)
	      paste(names(tg), "(", tg, ")")
            }))

Deepayan