我是R的新手,所以請原諒我的無知。我做了一個僞堆疊的barplot,其中我使用geom_bar在彼此的頂部繪製了4組條。三種橡樹(QUAG,QUKE,QUCH)有4種健康狀況類別(活着,死亡,感染,& sod-dead)。使用ggplot2包將圖例添加到「geom_bar」
我的代碼如下:
x <- as.data.frame(list(variable=c("QUAG", "QUKE", "QUCH"), alive = c(627,208,109), infected = c(102,27,0), dead = c(133,112,12), sod.dead=c(49,8,0)))
x.plot = ggplot(x, aes(variable, alive)) + geom_bar(fill="gray85") +
geom_bar(aes(variable,dead), fill="gray65") +
geom_bar(aes(variable, infected), fill="gray38") +
geom_bar(aes(variable, sod.dead), fill="black")+
opts(panel.background = theme_rect(fill='gray100'))
x.plot
現在我想打一個傳奇,顯示其灰色遮陽涉及到樹狀態,即「gray65」是「死樹「等等,我一直在嘗試過去的一小時,並且無法實現它的工作。
1爲簡潔再現的例子。 – mnel