[英]two bars next to each other using geom_bar
我有以下数据框
df
decades marxftext durkftext
1 1970-1979 3009 393
2 1980-1989 3468 469
3 1990-1999 3420 657
4 2000-2009 3162 700
而且我想绘制一个Marxftext和durkftext彼此相邻的条形图
我尝试了以下
melt(df,id.vars ='decades')
并得到了
decades variable value
1 1970-1979 marxftext 3009
2 1980-1989 marxftext 3468
3 1990-1999 marxftext 3420
4 2000-2009 marxftext 3162
5 1970-1979 durkftext 393
6 1980-1989 durkftext 469
7 1990-1999 durkftext 657
8 2000-2009 durkftext 700
如何使用geom_bar创建并排的条形图?
在这里分享一个样本,以防其他人想要改进它...
df <- data.frame(c("1970-1979", "1980-1989", "1990-1999"), c(3009, 3468, 3420), c(393, 469, 657))
colnames(df) <- c("decades", "marxftext", "durkftext")
require(ggplot2)
require(reshape2)
df <- melt(df, id = "decades")
ggplot() + geom_bar(data = df, aes(x = decades, y = value, fill = variable), position = "dodge", stat = "identity")
修改要求? 发表评论,我将发表修改
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.