My question is I want a divergent color for my heatmap using geom_tile
and the gradient color varies on both ends of the scale. For example, the whole scale is (-1,1), I only want the values from -1 to -0.5 and the values from 0.5 to 1.0 have gradient color variation and the values between -0.5 and 0.5 stays as white. However I can't find an option in scale_fill_gradient
to reach the goal. A reproducible example is as below and the data is from ggplot2 heatmaps: using different gradients for categories
nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv")
nba$Name <- with(nba, reorder(Name, PTS))
library("ggplot2")
library("plyr")
library("reshape2")
library("scales")
nba.m <- melt(nba)
nba.s <- ddply(nba.m, .(variable), transform,
rescale = scale(value))
ggplot(nba.s, aes(variable, Name))+geom_tile(aes(fill = rescale), colour = "white") +
scale_fill_gradient(low = "darkgreen", high = "darkred")