Panel functions are passed coordinates x
and y
, from the notation y ~ x
. Hence you write your panel function in terms of those arguments, not the names of your own data objects passed to those arguments. Then it works:
x <- rnorm (100)
z <- x + rnorm(100)
f <- gl(2,50,labels =c("Groups 1" , "Groups 2"))
df <- data.frame(x = x, z = z, f = f) ## I prefer objects in data frames
xyplot (z ~ x | f, data = df,
panel = function (x, y, ...) {
panel.xyplot(x, y, ...)
panel.abline(h = median(y),
lty=2
)
})