这与我刚问过的another问题密切相关。
这是我的数据:
y <- structure(c(0.5619, 0.4381, 0.7587, 0.2413, 0.8764, 0.1236, 0.9019,
0.0981, 0.9481, 0.0519, 0.99, 0.01),
.Dim = c(2L, 6L), .Dimnames = list(c("FALSE", "TRUE"), NULL))
y
# [,1] [,2] [,3] [,4] [,5] [,6]
# FALSE 0.5619 0.7587 0.8764 0.9019 0.9481 0.99
# TRUE 0.4381 0.2413 0.1236 0.0981 0.0519 0.01
每组中的相同颜色的原始图(蓝色和红色):
barplot(y, horiz = TRUE, col = c("blue", "red"),
names.arg = c("Overall", paste("Flag", 5:1)), las = 1,
cex.names = 0.6,
main = "Proportion Dropped Given Each Sample Restriction")
我想更改每个组的红色右侧栏,而是在每个组中包含不同的颜色,例如:
因此,我创建了一个新的col
向量,每个条形段都有一种颜色:
barplot(y, horiz =TRUE,
col = c("blue", "gold",
"blue", "springgreen",
"blue", "orange",
"blue", "red",
"blue", "white",
names.arg = c("Overall", paste("Flag", 5:1)), las = 1,
cex.names = 0.6,
main = "Proportion Dropped Given Each Sample Restriction"))
但是,只使用col
(蓝色和金色)中的前两种颜色,它们被循环使用6次:
有没有办法获得我正在寻找的输出?
答案 0 :(得分:2)
也许通过欺骗barplot
来思考还有更多类别。这非常难看,但它似乎完成了工作:
ymod <- cbind(c(y[,1], 0, 0,0,0,0,0,0,0,0,0),
c(0, 0, y[,2],0,0,0,0,0,0,0,0),
c(0, 0,0,0, y[,3],0,0,0,0,0,0),
c(0, 0,0,0,0,0, y[,4],0,0,0,0),
c(0, 0,0,0, 0,0,0,0,y[,5],0,0),
c(0, 0,0,0, 0,0,0,0,0,0,y[,6]))
barplot(ymod, horiz=T,
col=c(rbind(rep("blue",6),c("white","red","purple",
"orange","springgreen","gold"))))