【发布时间】:2012-10-23 16:40:00
【问题描述】:
我正在尝试在ggplot2 中叠加条形图
我当前的代码会生成一个条形图,但它们是堆叠在一起的。我不想要这个,我希望将它们叠加起来,这样我就可以看到每个条形高度的差异。
代码:
library(ggplot2)
library(reshape)
x = c("Band 1", "Band 2", "Band 3")
y1 = c("1","2","3")
y2 = c("2","3","4")
to_plot <- data.frame(x=x,y1=y1,y2=y2)
melted<-melt(to_plot, id="x")
print(ggplot(melted,aes(x=x,y=value,fill=variable)) + geom_bar(stat="identity", alpha=.3))
堆叠输出:
【问题讨论】: