Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't R's heatmap function color cells consistently?

Tags:

r

heatmap

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: here

Can anyone explain what's happening here?

like image 325
wvoq Avatar asked May 31 '12 20:05

wvoq


People also ask

What does white mean in a heat map?

A row of white means "no variation".

Can you create a heat map in R?

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.


1 Answers

By default heatmap scales by "row".

heatmap(cor.matrix,Rowv=NA,Colv=NA, scale="none")
like image 84
IRTFM Avatar answered Nov 15 '22 10:11

IRTFM