[R] lattice panels with grouped extra data as text?

Rainer Hurling rhurlin at gwdg.de
Thu Jan 26 17:33:51 CET 2012


I have a problem with including extra data in a lattice graphic. I am 
trying to put some calculated values in an extra column of a boxplot. A 
minimal example should show what I am trying to do:


foo <- data.frame(
   Treatment=rnorm(1:12,2),
   Variant=c("A","A","B","C","D","C","B","D","D","B","B","A"),
 
Szenario=c("Dry","Wet","Dry","Dry","Wet","Dry","Wet","Wet","Dry","Wet","Dry","Dry"),
   Area=c(sample(100, 12))
                   )

require(lattice)
require(latticeExtra)

bwplot(Treatment ~ Variant | Szenario,
        data=foo,

        panel = function(...) {
          # Marking the extra column yellow
          panel.xblocks(c(4.5,5.0),
                        c(rgb(255,255,0, alpha=127, max=255),
                          rgb(255,255,0, alpha=127, max=255)))
          # Put in the extra values (instead of a string)
          panel.text(5, min(foo$Treatment), "sum of foo$area per panel", 
srt=90, adj=c(0,0.5), cex=2)

          panel.bwplot(...)
        },

        # Create extra space for a column
        xlim=range(0.5,5.5),
        scales = list(x = list(labels=c(NA,"A","B","C","D","")))
        )


I would like to put summarized area values (from Foo$Area) in the yellow 
coloured columns of each panel. So afterwards there should be one sum in 
the first panel and another sum in the next panel (and so on, if more 
than two panels).

It tried a little bit with groups and group.number but without success.

Is there any easy solution for this?

Any help is really appreciated.
Rainer Hurling



More information about the R-help mailing list