[R] annotating an axis in bwplot (lattice)

Sebastian Luque
2005-09-22T22:03:37Z

Hi Deepayan,


Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote:

[...]

> 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, ")")
> }))

Thanks, this is almost what I was looking for.  Because I needed the
frequency of each group in *each* panel, I modified your suggestion like
(omitting the panel function for briefness):

--8<---------------cut here---------------start------------->8---
with(subset(dd, age > 20),
     bwplot(grp ~ age | sex, aspect = 0.5, box.ratio = 2,
            scales = list( y = list(relation = "free")),
	    ylim = {
	      tgf <- table(grp[sex == "Female"])
              tgm <- table(grp[sex == "Male"])
              list(paste(names(tgf), "(", tgf, ")"),
                   paste(names(tgm), "(", tgm, ")"))
            }))
--8<---------------cut here---------------end--------------->8---

One has to be careful though with the order of panels.


Thank you,

--
Sebastian P. Luque