如何在不同的地塊上將相同的顏色固定在一個值上?ggplot2:如何在相同的因子在不同的地塊使用相同的顏色
說我有兩個data.frames DF1和DF2:
library(ggplot2)
library(gridExtra)
set.seed(1)
df1 <- data.frame(c=c('a', 'b', 'c', 'd', 'e'), x=1:5, y=runif(5))
df2 <- data.frame(c=c('a', 'c', 'e', 'g', 'h'), x=1:5, y=runif(5))
當他們使用C作爲顏色指示劑繪製我得到同樣的五種顏色。
g1 <- ggplot(df1, aes(x=x, y=y, fill=c)) + geom_bar(stat="identity")
g2 <- ggplot(df2, aes(x=x, y=y, fill=c)) + geom_bar(stat="identity")
grid.arrange(g1, g2, ncol=2)
但我想是c的值相同會得到相同的顏色。
只是在我的例子中,我把兩個地塊在一起。我真正的問題是由許多獨立的情節組成。 – JerryWho