2013-12-11 27 views
6

Le funzioni geom_tile e scale_fill_gradient producono belle mappe termiche. Come aggiungere etichette alle tessere ggplot2, in modo che su ciascuna tessera venga stampato il rispettivo valore?Come mettere le etichette sulle tessere in ggplot2 in R?

PS: Ci sono molti pacchetti che eseguono heatmap con un successo vairous (ad esempio, un sondaggio è qui: drawing heatmap with dendrogram along with sample labels). Ma sono interessato alla soluzione ggplot2, se possibile.

Un esempio piccolo codice (senza etichette):

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") 

risposta

11

Just:

+geom_text(aes(label=val.mean)) 
Problemi correlati