I have a lattice plot of experimental data that has 4 datasets (i.e. 4 different subsets in \"Config.\" below), each dataset subdivided according to the config and then also gro
This is best accomplished using panel.number()
, which gives you access, inside the call to a custom panel function, to the index of the panel being currently plotted.
Here's a simple reproducible example:
library(lattice)
lattice.options(default.theme = standard.theme(color = FALSE))
COLORS = c("blue", "gold", "red", "green", "black", "grey")
xyplot(mpg ~ disp | carb, data = mtcars,
panel = function(x,y,...) {
panel.xyplot(x, y, col=COLORS[panel.number()], pch=16, ...)
})
A couple more involved examples are given here and here.