2014-11-06 206 views
2

我有來自兩種植物的氣體排放的時間數據,這兩種植物都經歷了相同的處理。對於一些previous help得到這個代碼放在一起[編輯]:R並排分組boxplot

soilflux = read.csv("soil_fluxes.csv") 
library(ggplot2) 
soilflux$Treatment <- factor(soilflux$Treatment,levels=c("L-","C","L+")) 
soilplot = ggplot(soilflux, aes(factor(Week), Flux, fill=Species, alpha=Treatment)) + stat_boxplot(geom ='errorbar') + geom_boxplot() 
soilplot = soilplot + labs(x = "Week", y = "Flux (mg m-2 d-1)") + theme_bw(base_size = 12, base_family = "Helvetica") 
soilplot 

生產這種效果很好,但有其缺陷。

img

雖然它傳達我需要它的所有信息,儘管谷歌拖網,從這裏看我只是不能讓傳說的「治療」部分顯示,L-輕,L +最黑暗的。我也被告知,單色配色方案更容易區分,因此我試圖獲得類似this的圖例,其中圖例清晰。

img

回答

1

正如你可以從speciestreatment創建一個綜合係數和手動指定填充顏色變通方法:

library(ggplot2) 
library(RColorBrewer) 
d <- expand.grid(week = factor(1:4), species = factor(c("Heisteria", "Simarouba")), 
       trt = factor(c("C", "L-", "L+"), levels = c("L-", "C", "L+"))) 

d <- d[rep(1:24, each = 30), ] 
d$flux <- runif(NROW(d)) 

# Create a combined factor for coding the color 
d$spec.trt <- interaction(d$species, d$trt, lex.order = TRUE, sep = " - ") 

ggplot(d, aes(x = week, y = flux, fill = spec.trt)) + 
    stat_boxplot(geom ='errorbar') + geom_boxplot() + 
    scale_fill_manual(values = c(brewer.pal(3, "Greens"), brewer.pal(3, "Reds"))) 

grouped boxplot

+0

我傾向於同意,這兩個尺度混合成其實可能是更好的解決方案。使用離散的alpha值(大於2)與不同的顏色組合使得眼睛難以比較並找出哪些級別匹配在一起,等等。此外,獨特的比例顯示所有可能的顏色組合,因爲2級解決方案沒有。 – agenis 2014-11-06 14:37:51

+0

工作出色,非常感謝你的幫助! – welcbw 2014-11-06 15:28:13

+1

非常歡迎。如果有效,你能否也接受答案? – thothal 2014-11-06 16:28:23