在R studio中用barplot分组有价值的

时间:2015-12-30 02:46:16

标签: r data-visualization

Income1.csv
  Age.Group     X   X.1   X.2   X.3  X.4
1    Income 16-24 25-34 35-44 45-54  55+
2       Low  13.9  17.4  14.9  11.9 10.9
3    Medium  26.3  46.9  42.2  30.7 21.5
4      High  11.6  19.7  22.4  17.4  6.7

如何创建高度为Age的分组条形图?下面的图片是我想要创建的。

enter image description here

1 个答案:

答案 0 :(得分:0)

阅读您的数据:

d <- dput(d)
structure(list(Income = structure(c(2L, 3L, 1L), .Label = c("High", 
"Low", "Medium"), class = "factor"), `16-24` = c(13.9, 26.3, 
11.6), `25-34` = c(17.4, 46.9, 19.7), `35-44` = c(14.9, 42.2, 
22.4), `45-54` = c(11.9, 30.7, 17.4), `55+` = c(10.9, 21.5, 6.7
)), .Names = c("Income", "16-24", "25-34", "35-44", "45-54", 
"55+"), class = "data.frame", row.names = c(NA, -3L))

绘制数据:beside指定将值绘制在未堆叠的旁边。

barplot(as.matrix(d[,-1]), beside = T, legend.text = d$Income)