I need to use xyplot in combination with dlply, to plot on several pages. Following the example below, one page for each value of x, conditioning on y:
set.seed(1)
df <- as.data.frame(cbind(
x = c("AV","DZ"),
y=rep(c(letters[1:4]),5),
stringsAsFactors = F))
df$z <- rnorm(20)
df$q <- rnorm(20)
plotter <- function(dataframe) { xyplot(q ~ z | y, data=dataframe)}
charts <- dlply(df, .(x), plotter)
charts
Now, if I want to change the color of the strip background (as usefully explained here), should I pick the value of the color from a list as well? Should I use a list of vectors? A dataframe? A combination of x
& y
values? Two nested plyr
functions?
Let's suppose that the four panel colours should be the following:
"blue" "red" "blue" "green"
How would you suggest to modify the col
parameter in the myStripStyle
function (proposed in the link) that follows?
bgColors <- c("black", "green4", "blue", "red", "purple", "yellow")
txtColors <- c("white", "yellow", "white", "white", "green", "red")
# Create a function to be passed to "strip=" argument of xyplot
myStripStyle <- function(which.panel, factor.levels, ...) {
panel.rect(0, 0, 1, 1,
col = bgColors[which.panel],
border = 1)
panel.text(x = 0.5, y = 0.5,
font=2,
lab = factor.levels[which.panel],
col = txtColors[which.panel])
}
To be honest, I think that this question could have already been answered somewhere else, but I couldn't find any mix of plyr
functions and lattice
graphics that could help me to change parameters in this way.