The heatmap
function in R is supposed to help a human being interpret the relative values of the elements of a matrix. However, it seems not to color cells consistently within a given plot, which is a severe obstacle to interpreting the relative values correctly.
For example, let's generate some data by concatenating columns of normal random variates:
foo <- cbind(replicate(10,rnorm(10)))
Now if we correlate the columns of foo, we can verify that we get 1's in the diagonal entries since the correlation of any column with itself is 1:
cor.matrix <- cor(foo)
But when we plot:
heatmap(cor.matrix,Rowv=NA,Colv=NA)
(we're suppressing the dendrogram reording here, although that doesn't seem to matter)
the diagonal cells are not colored uniformly, as you can see:
Can anyone explain what's happening here?
A row of white means "no variation".
The most basic heatmap you can build with R, using the heatmap() function. Control the color palette used in the heatmap. Several methods shown. Add color beside the heatmap to compare actual structure with the expected one.
By default heatmap scales by "row".
heatmap(cor.matrix,Rowv=NA,Colv=NA, scale="none")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With