[R] learning about panel functions in lattice

Juliet Hannah juliet.hannah at gmail.com
Sun Jun 14 21:50:05 CEST 2009


Hi All,

I am trying to understand panel functions. Let's use this example.


library(lattice)
time<-c(rep(1:10,5))
y <-time+rnorm(50,5,2)
group<-c(rep('A',30),rep('B',20))
subject<-c(rep('a',10),rep('b',10),rep('c',10),rep('d',10),rep('e',10))
myData <-data.frame(subject,group,time,y)
head(myData)

Plot 1

xyplot(y ~ time | group, data = myData, groups = subject,
       panel = panel.superpose,
       panel.groups = function(...)
       panel.loess(...)
       )


Plot 2

xyplot(y ~ time | group, data = myData, groups = subject,
       panel = function(...) {
       panel = panel.superpose(...)
       panel.groups = function(...)
       panel.loess(...)
       })

Why does Plot 2 not produce the loess curves? Why are points not
plotted on Plot 1?

Plot 3

xyplot(y ~ time | group, data = myData, groups = subject,
        panel = function(...) {
          panel.superpose(...)
          panel.superpose(panel.groups = panel.loess, ...)
        })

What is the effect of writing panel.superpose twice? What is it about
this call that makes the data points
appear on the graph?


Thanks,

Juliet




More information about the R-help mailing list