Hi, I am trying to create facet plot and want to set different panel background color for each plot in order to classify the individual facets into two or three groups.
For example,
library(ggplot2)
dat <- expand.grid(list(
x = letters[1:3],
y = LETTERS[1:4],
z = c("M1", "M2", "M3")
))
dat$value <- rnorm(36)
ggplot(dat, aes(z,value)) +
geom_point() +
geom_line(group = 1) +
facet_grid(x ~ y)
Here is a hack that might get you what you need. I requires making a data frame with your faceting variables, assigning each row to a group, and using that group as the fill variable.