2012-04-06 20 views
9

Vorrei creare una heatmap tramite il comando heatmap.2() con un tasto colorato centrato su 0 (cioè colore bianco -> 0, rosso -> maggiore di 0, blu -> minore di 0) pur mantenendo la scala = "none" poiché sono interessato a tracciare una mappa termica dei valori effettivi. Tuttavia, tutte le mie mappe di calore non sono centrati sullo zero su utilizzando la seguente riga:R: Centratura tasto heatmap.2 (pacchetto gplots)

library(gplots) 
outputHeatmap <- heatmap.2(heatmapInputActual, dendrogram="none", Rowv=FALSE, 
    Colv=FALSE, col= bluered(256), scale="none", key=TRUE, density.info="none", 
    trace="none", cexRow=0.125, cexCol=0.125, symm=FALSE, symkey=TRUE) 

ho pensato che con il comando SymKey = TRUE avrebbe funzionato, ma non è così. La variabile che sto provando a fare una heatmap di è una (n x 3) matrice di valori numerici. Segue un input problematico per il comando heatmap.2() sopra riportato:

8.408458 5.661144 0.00000000 
4.620846 4.932283 -0.46570468 
-4.638912 -3.471838 -0.12146109 
-4.822829 -3.946024 0.06403327 
3.948832 4.520447 -0.31945941 

Grazie per il vostro tempo. Non vedo l'ora di ricevere le tue risposte.

risposta

10

La soluzione sembra essere solo aggiungendo symbreaks al tuo heatmap.2. Ecco un esempio completamente riproducibili con i tuoi dati:

library(gplots) 
#read your example data 
heatmapInputActual <- read.table(textConnection(
"8.408458 5.661144 0.00000000 
4.620846 4.932283 -0.46570468 
-4.638912 -3.471838 -0.12146109 
-4.822829 -3.946024 0.06403327 
3.948832 4.520447 -0.31945941 
"),as.is=TRUE) 
#convert sample data to matrix 
heatmapInputActual <- as.matrix(heatmapInputActual) 
#just add symbreaks to the end of your code 
heatmap.2(heatmapInputActual, dendrogram="none", Rowv=FALSE, Colv=FALSE, 
      col = bluered(256), scale="none", key=TRUE, density.info="none", 
      trace="none", cexRow=0.125, cexCol=0.125, symm=F,symkey=T,symbreaks=T) 

enter image description here

+1

Yup! Questa dovrebbe essere la risposta accettata. – Noah

+0

Dopo aver eseguito lo stesso identico codice, non ho ricevuto la chiave colore! –

+0

@ayeshamalik non so perché, lavora per me. Il pacchetto R e gplots è aggiornato? –