2009/6/14 Juliet Hannah juliet.han...@gmail.com:
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?
The above creates a function called panel.groups within the anonymous
panel function but that is meaningless. In particular, its not even
accessible outside of the anonymous function and is never called
within the anonymous function so its never called at all.
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?
The first superpose draws the points and the second draws the
loess curve. Try instrumenting it with browser() calls (resulting
in a pause) and also adding a col attribute and it will become clearer:
xyplot(y ~ time | group, data = myData, groups = subject,
panel = function(...) {
browser()
panel.superpose(..., col = purple)
browser()
panel.superpose(panel.groups = panel.loess, col = green, ...)
browser()
}
)
Thanks,
Juliet
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.