Specifying same limits for colorbar (legend) in ggplot2

Viewed 10097

I want multiple plots to share the same color-scale. A given value in one plot should have the same color as in the second plot. How do I enforce this with ggplot2?

Here is an example of two plots that do not share color-scales, but should:

x <- matrix(1:16, 4)
y <- matrix(1:16-5, 4)
library(reshape)
ggplot(data = melt(x)) + geom_tile(aes(x=X1,y=X2,fill = value))
ggplot(data = melt(y)) + geom_tile(aes(x=X1,y=X2,fill = value))

These two plots look the same, but they should look different!

1 Answers
Related