2014-09-01 86 views
2

我無法將barplot中的歸因顏色歸爲行,但它們不存在。當我使用命令:在一個barplot中按行排列屬性顏色

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種顏色隨機選擇,對他們沒有具體的意義。

我在做什麼錯?

回答

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 
     ) 

這是你希望得到什麼?

enter image description here

+0

是的,非常相似,只有22色和x軸427值。但這是我正在尋找的。爲什麼不開採工作?我確定它也是一個矩陣。 – 2014-09-01 13:40:36

+0

在barplot中設置'border = FALSE'。 – zx8754 2014-09-01 13:45:05

+0

伎倆 – 2014-09-01 13:49:04