我是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