您需要設置範圍(色條的限制)同樣爲所有的人,還可以指定顏色之間的界限爲了它。
rng = range(matrixA, matrixB, matrixC)
並添加到您的ggplot
代碼:
g + scale_fill_gradient2(low="green", mid="lightblue", high="red", #colors in the scale
midpoint=mean(rng), #same midpoint for plots (mean of the range)
breaks=seq(0,1,0.25), #breaks in the scale bar
limits=c(floor(rng[1]), ceiling(rng[2])))
例子:
下面是一個例子,可以幫助你得到你想要的東西:
x <- matrix(60:85, 5)/100
y <- matrix(65:95, 5)/100
z <- matrix(50:100, 5)/100
rng = range(c((x), (y), (z)))
library(reshape)
library(ggplot2)
ggplot(data = melt(x)) + geom_tile(aes(x=X1,y=X2,fill = value)) +
scale_fill_gradient2(low="green", mid="lightblue", high="red", #colors in the scale
midpoint=mean(rng), #same midpoint for plots (mean of the range)
breaks=seq(0,1,0.25), #breaks in the scale bar
limits=c(floor(rng[1]), ceiling(rng[2]))) + #same limits for plots
ggtitle("X")
ggplot(data = melt(y)) + geom_tile(aes(x=X1,y=X2,fill = value)) +
scale_fill_gradient2(low="green", mid="lightblue", high="red",
midpoint=mean(rng),
breaks=seq(0,1,0.25),
limits=c(floor(rng[1]), ceiling(rng[2]))) +
ggtitle("Y")
ggplot(data = melt(z)) + geom_tile(aes(x=X1,y=X2,fill = value)) +
scale_fill_gradient2(low="green", mid="lightblue", high="red",
midpoint=mean(rng),
breaks=seq(0,1,0.25),
limits=c(floor(rng[1]), ceiling(rng[2]))) +
ggtitle("Z")
這將給你:
PLS提供通過提供您的數據的[再現的示例](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ,或者對它們進行模擬。使用'dput(mat.melted)'並將結果粘貼到問題中。順便說一句我想你說的是data.frames,而不是matrix-es – GGamba