堆积条形图始终按填充对同一条形图上的段进行排序。如何避免这种情况?我想要实现的是一个堆叠的条形图,带有交替的蓝色和红色段(代表状态转换)
问问题
232 次
1 回答
1
Base graphics solution
Use the col
argument of barplot
:
d <- rep(1, 4)
d <- as.matrix(d, nrow=4, ncol=1)
barplot(d, beside=FALSE, col=c("red", "blue", "red", "blue"))
ggplot solution
require(ggplot2)
redBlue <- rep(c("red", "blue"), length(levels(diamonds$color)))
#redBlue is twice as long as necessary, but that's harmless
ggplot(diamonds, aes(x=clarity, fill=color)) + geom_bar() +
scale_fill_manual(values=redBlue)
于 2012-12-10T21:32:54.973 回答