I want to create a heat map where with a color pallet from green to red, but the values ββ0 are in white. I started with a geom_tile heatmap with various fill colors based on factor and others on SO, but can't get what I need. For example, with the following database:
df <- data.frame(expand.grid(1:10,1:10)) df$z <- sample(0:10, nrow(df), replace=T)
I can create this plot:
ggplot(df,aes(x = Var1,y = Var2,fill = z)) + geom_tile() + scale_fill_gradient(low = "green", high = "red")
But I want the values ββequal to zero to be white. So this becomes part of:
ggplot(df,aes(x = Var1,y = Var2,fill = z)) + geom_tile() + scale_fill_gradient(low="green", high="red", limits=c(1, 10))

And this gets 0 as white, but I lose green to red:
ggplot(df,aes(x = Var1,y = Var2,fill = z)) + geom_tile() + scale_fill_gradient(low = "white", high = "red")

And I can't use the brewer scales at all (although I think I am missing something simple based on error).
ggplot(df,aes(x = Var1,y = Var2,fill = z)) + geom_tile() + scale_fill_brewer("Greens")
Error: continuous value applied to discrete scale
Should I just replace 0 with NA? Any help would be greatly appreciated.