有没有办法根据随数据框提供的变量填充使用facet_wrap创建的facet条?
示例数据:
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")))
示例图:
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)
我知道如何更改条带的背景颜色(例如橙色):
p1 + theme(strip.background = element_rect(fill="orange"))

有没有办法转嫁值的变量size中MYdata的参数fill的element_rect?
基本上,对于所有条带而不是1种颜色,我希望小水果(苹果,李子,梨)的条带背景颜色为绿色,大果实(橙色,香蕉,葡萄)的背景颜色为红色.