library(ggplot2)
library(cumplyr)
library(scales)
library(RColorBrewer)
myPalette <- colorRampPalette(rev(brewer.pal(11, \"Spectral\")))
x = 1:5
y = 1:5
pt
In scale_fill_gradientn set the limits to be the same, so for example:
scale_fill_gradientn(colours = myPalette(4),limits=c(0,4))
And this is p1 and p2:
Use limit
in scale_gradientn
:
p1 <- ggplot(as.data.frame(d1))
p1 <- p1 + geom_tile(aes(x = x, y = y, fill = val))
p2 <- ggplot(as.data.frame(d2), aes(x = x, y = y, fill = val))
p2 <- p2 + geom_tile(aes(x = x, y = y, fill = val))
library(gridExtra)
p1 <- p1 + scale_fill_gradientn(colours = myPalette(4), limits=c(0,4))
p2 <- p2 + scale_fill_gradientn(colours = myPalette(4), limits=c(0,4))
grid.arrange(p1, p2)
The grid.arrange
stuff is just to avoid me having to copy/paste two pictures.