[英]Using Geom_Bar in GGplot2
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. 所以我试图在ggplot2中使用geom_bar,我在网上展示它的所有情况都是某些事物的比较频率。 The chart that I'm trying to do is the stacked bar graph like this one
我想要做的图表是像这样的堆积条形图
However, I want to do it from a vector of values. 但是,我想从一个值向量中做到这一点。 That is, let's say I have the vector
也就是说,让我说我有矢量
v=c(1,2,3,4)
Instead of 4 even bars, which is what I understand I would get, I'd like a stack of 4 bars where the top one is 1 unit tall, and the next one down is 2 units tall (etc.). 而不是4个偶数条,这是我理解的我会得到的,我想要一堆4个条形,其中顶部的一个是1个单位高,下一个是2个单位高(等)。 Is this possible in R?
这可能在R?
Edit: Here is the code that I've used for my graph. 编辑:这是我用于图表的代码。 It's yielding a normal bar graph, not the stacked version that I'm looking for:
它产生了一个正常的条形图,而不是我正在寻找的堆叠版本:
ggplot(data = v, aes(x = factor(x), y = y)) + geom_bar(aes(fill = factor(y)),stat = 'identity')
I think you can start from this: 我想你可以从这开始:
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.