2016-12-12 47 views
0

使用鹼的圖形,我有一個條形圖像這樣的R:跨越杆改變顏色在堆積條形圖

a <- c(1,2,3); b <- c(1,1,1) 
barplot(rbind(a,b), col=c("red","gray")) 

enter image description here

在頂部和紅色在底部每個條灰色。不過,我希望每個酒吧都能改變底部的顏色,並保持頂部的灰色。

cols <- c(rbind(c("red","green","blue"),"gray")) 
barplot(rbind(a,b), col=cols) 

沒有成功。有沒有其他方法?

回答

1

不是最優雅的方式,但這個工程。

a<-c(1,1,1) 
b<-c(1,0,0) 
c<-c(0,2,0) 
d<-c(0,0,3) 

cols <-c("red","green","blue","gray") 
# notice order of rbind... a is last 
barplot(rbind(b,c,d,a), col=cols) 

enter image description here