有沒有一種方法可以根據數據框提供的變量填充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