I want to make a heatmap in ggplot2. My toy data and code is:
set.seed(12345)
dat <-
data.frame(
Row = rep(x = LETTERS[1:5], times = 10)
, Co
You have several options for something like this, but here is one as a starting point.
First, use cut to create a factor from Y with the appropriate ranges:
dat$Y1 <- cut(dat$Y,breaks = c(-Inf,-3:3,Inf),right = FALSE)
Then plot using a palette from RColorBrewer:
ggplot(data = dat, aes(x = Row, y = Col)) +
geom_tile(aes(fill = Y1), colour = "white") +
scale_fill_brewer(palette = "PRGn")

This color scheme is more purple than blue on the low end, but it's the closest I could find among the brewer palette's.
If you wanted to build your own, you could simply use scale_fill_manual and specify your desired vector of colors for the values argument.