0

I want to change the color of the text in a panel strip for a lattice plot, based on a condition. Let's assume I'm working on the following dummy dataframe and scatterplot:

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

I want to set the par.strip.text color variable col equal to "red" if the mean of df$q is less than zero, "blue" otherwise. How would you suggest to proceed? I've tried something like if-else condition, but I felt lost after a few attempts.

On a more general note, I'd really appreciate any suggestion on how highlighting some panels based on conditions in a multipanel plot like this.

EDIT
The difference with the question that was already answered is that I need to use xyplot in combination with dlply, to plot on several pages. Following the example above, one page for each value of x, conditioning on y (I've edited the code to reflect more accurately the situation).
Now, if I want to change the color of the strip background (as usefully suggested in the comment), should I pick the value of the color from a list as well? Should I use a list of vectors? A dataframe? Let's suppose that the four panel colours should be the following:

[1] "blue"  "red"   "blue"  "green"

How would you suggest to modify the myStripStyle function proposed in the link?

MaZe
  • 239
  • 1
  • 4
  • 13

0 Answers0