So I'm trying to use geom_bar in ggplot2, and all of the cases that I see of people demonstrating it online are of comparative frequencies of certain things. The chart that I'm trying to do is the stacked bar graph like this one ![stacked bars](https://i.stack.imgur.com/XLa2t.png)
但是,我想从值向量来做到这一点。也就是说,假设我有向量
v=c(1,2,3,4)
我想要一堆 4 个条形,其中顶部的条形高度为 1 个单位,下一个条形的高度为 2 个单位,而不是 4 个偶数条形,这就是我所理解的。这在 R 中可能吗?
编辑:这是我用于图表的代码。它产生一个正常的条形图,而不是我正在寻找的堆叠版本:
ggplot(data = v, aes(x = factor(x), y = y)) + geom_bar(aes(fill = factor(y)),stat = 'identity')
我想你可以从这个开始:
v=data.frame(x="My Stacked Bar", y=c(1,2,3,4))
ggplot(data = v, aes(x = factor(x), y = y))+
geom_bar(aes(fill=factor(y)), stat="identity")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)