2

我无法将条形图中的颜色归因于行,它们不存在。当我使用命令时:

barplot(data[,3:429])

它确实给了我正确的高度模式,但它全是黑色的。我有 22 行不同的行(每行有 427 个变量),但这些行在我的图中没有识别。

一小部分数据如下所示:

VT  ATC V4  V5  V6  V7  V8  V9  V10 V11 V12 .... V429
1   1   0   1   1   2   2   2   2   1   1
1   2   0   1   1   1   1   1   1   1   1
1   3   0   0   0   0   0   0   0   0   0
1   4   0   0   0   0   0   0   0   0   0
1   5   0   0   0   1   1   1   1   0   0

我试过添加颜色,但它不是这样工作的:

barplot(data[,3:429],col=c("blue", "aliceblue","antiquewhite", "antiquewhite1","antiquewhite2","antiquewhite3", "antiquewhite4","aquamarine","aquamarine1","aquamarine2", "aquamarine3", "aquamarine4", "darkgreen", "darkgrey","darkkhaki","darkmagenta", "darkolivegreen","darkolivegreen1","darkolivegreen2","darkolivegreen3","darkolivegreen4","darkorange"))

这 22 种颜色是随机选择的,它们没有特定的含义。

我究竟做错了什么?

4

1 回答 1

1

以下对我有用:

#dummy data
m <- matrix(sample(1:10,500*22,replace=TRUE),ncol=500)

#stacked bar plot with colours
barplot(m[,3:400],
        col=c("blue", "aliceblue","antiquewhite", "antiquewhite1","antiquewhite2","antiquewhite3", "antiquewhite4","aquamarine","aquamarine1","aquamarine2", "aquamarine3", "aquamarine4", "darkgreen", "darkgrey","darkkhaki","darkmagenta", "darkolivegreen","darkolivegreen1","darkolivegreen2","darkolivegreen3","darkolivegreen4","darkorange"),
        border = FALSE, space=0
        )

这是你期望得到的吗?

在此处输入图像描述

于 2014-09-01T13:34:07.513 回答