2016-12-12 46 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