按照特定的填充颜色顺序叠加直方图

时间:2015-07-04 01:55:13

标签: r ggplot2

在ggplot中使用geom_histogram和position =" identity"是否可以选择首先出现颜色的顺序?

a <- data.frame(rep(1:10, each = 4))
b <- data.frame(rep(1:3, each = 5))
c <- data.frame(rep(4:9, each = 3))
names(a) <- "num"
names(b) <- "num"
names(c) <- "num"
a$color <- "red"
b$color <- "white"
c$color <- "blue"

abc <- rbind(a,b,c)

ggplot() + geom_histogram(data = abc, aes(x=num, fill = color),
position = "identity") + scale_fill_identity()

是否可以绘制白色,然后是红色然后是蓝色?

1 个答案:

答案 0 :(得分:2)

两种方式

apply

enter image description here