I would like to get a customized legend for the ready heat map graph, so as it ranged from 0 to 1 with gray scale, but value before 0.01 remain white without any colour gradient on it. Managed to do it for the heat map graph but can't find any close example for the legend.
Here is my code:
> ggplot(heatmap,aes(Colour, Group, fill=p.value))+
+ scale_fill_gradientn(colours= c("white","gray","black"), values=c(0,0.011,1), breaks=c(0,0.01,0.25,0.5,0.75,1), guide=guide_colorbar(frame.colour="black"))+
+ geom_tile() + theme_bw()+ theme(legend.key.height=unit(4.5,"cm"))
and a screenshot for the heat map graph:
Any suggestion?
Update: I was substituting the second color from "gray" to "gray95" and it looked slightly better than the graph shown. Kind of delaying the start region for the gray colour to above 0.01 (compared to the legend in the shown graph, where the gray started somewhere before 0.01). Thanks both @Nate and @tjebo for the suggestion on this! However, any helpful suggestion is still welcome.
Also, just want to clarify that I was using "white" as a representation for a specific situation, where the colour "white" was not intended to be in the range for colour gradient for the legend.