The geom_tile and scale_fill_gradient create nice scale_fill_gradient . How to add labels to ggplot2 tiles so that each tile has its own meaning printed above it?
PS: There are many packages that make heatmaps with a high degree of success (for example, a review here: drawing a heatmap with a dendrogram along with sample labels ). But I'm interested in the ggplot2 solution, if possible.
An example of a small code (without labels):
library(Hmisc) library(ggplot2) df <- data.frame(row=sample(c("A", "B"), 10, replace=T), col=sample(c("x", "y"), 10, replace=T), val=rnorm(10)) sdf <- summaryBy(val~row+col, data=df, FUN=mean) ggplot(sdf, aes(x=row, y=col)) + geom_tile(aes(fill = val.mean), colour = "white") + scale_fill_gradient(low = "white", high = "yellow")
source share