有没有一种方法可以根据数据框提供的变量填充facet_wrap创建的构面条?ggplot2:facet_wrap基于数据集中变量的条纹颜色
实施例的数据:
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"))
有没有办法在MYdata
转嫁值的变量size
到参数fill
在element_rect
?
基本上,而不是所有条的颜色1,我想小条水果(苹果,李子,梨)的条形背景颜色为绿色,大水果(橙色,香蕉,葡萄)的背景颜色为红色。
有ISN尽管如此,在另一个网站上,这是一种简单的方法,[之前已经询问过](https://groups.google.com/forum/#!topic/ggplot2/fNBQrBPPbPM)。 – nograpes
谢谢,nograpes。我看了看,却找不到之前询问过的地方。 – Dalmuti71
如果你得到这个代码的工作,你应该把它作为一个答案。 – nograpes