Is there a way to fill the strips of facets created with facet_wrap based on a variable supplied with the data frame?
Example data:
MYdata <- data.frame(fruit = rep(c("apple", "orange", "plum", "banana", "pear", "grape")), farm = rep(c(0,1,3,6,9,12), each=6), weight = rnorm(36, 10000, 2500), size=rep(c("small", "large")))
Example plot:
p1 = ggplot(data = MYdata, aes(x = farm, y = weight)) + geom_jitter(position = position_jitter(width = 0.3), aes(color = factor(farm)), size = 2.5, alpha = 1) + facet_wrap(~fruit)
I know how to change the background color of the strips (e.g. to orange):
p1 + theme(strip.background = element_rect(fill="orange"))
Is there a way to pass on the values in the variable size
in MYdata
to the parameter fill
in element_rect
?
Basically, instead of 1 color for all strips I would like the strip background color of small fruits (apple, plum, pear) to be green and the background color of large fruits (orange, banana, grape) to be red.