[R] annotating an axis in bwplot (lattice)

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Sep 23 00:44:50 CEST 2005


On 9/22/05, Sebastian Luque <spluque at gmail.com> wrote:
> 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):

This might be a better approach then:

bwplot(grp ~ age | sex, aspect = 0.5, box.ratio = 2,
       scales = list(y = "free", rot = 0),
       prepanel = function(x, y, ...) {
           tg <- table(y);
           list(ylim = paste(names(tg), "(", tg, ")"))
} )

Deepayan




More information about the R-help mailing list