Reputation: 77
I have a working heatmap, built with gplots
, as shown here:
heatmap.2(as.matrix(matrix1),cellnote=as.matrix(matrix1),
notecol="black",margins =c(9,6),trace="none",density.info="none",
col=my_palette,Rowv=NA,Colv=NA,dendrogram="none",scale="row")
The underlying data in matrix1
looks as follows:
A AA AAA BBB CASH
CASH 0 0 0 0
JSUB 0.22171 0 0 2.20712
SECR 2.92828 1.97112 3.53786 0.91444
SENR 18.86672 11.53339 15.06844 21.57709
SSEN 5.707 1.96225 0.57815 2.93462
SSUB 0.36507 0.07968 0 0.44985
SUB 1.0539 0 0 2.37103
T1 0 0 0 0.56024
T2 1.87901 0 0 3.00718
UT2 0 0 0 0.15787
My matrix1
, which was created as a pivot table with the cast
function using the reshape
package, contains many zeroes. Whenever the value in my matrix is zero, I would not want to display a 'cellnote', as this merely confuses the heatmap.
I have however, so far, not figured out how to do this and am grateful for any advice.
Thank you!
Upvotes: 0
Views: 1811
Reputation: 8601
For me it works just to make a new matrix replacing zeros with NAs and pass this as the argument to cellnote
.
matrix2 <- as.matrix(matrix1)
matrix2[matrix2 == 0] <- NA
Re-running the code using matrix2
heatmap.2(as.matrix(matrix1),cellnote=matrix2,
notecol="black",margins =c(9,6),trace="none",density.info="none",
col=my_palette,Rowv=NA,Colv=NA,dendrogram="none",scale="row")
(By the way you didn't give my_palette
, so I hashed it out for this example.)
Upvotes: 1