I just noticed that the plots from using heatmap()
function and image()
function look different even though I'm using the same data matrix. I have the following code:
set.seed(12345)
dataMatrix <- matrix(rnorm(400), nrow =40)
set.seed(678910)
for(i in 1:40) {
# flip a coin
coinFlip <- rbinom(1, size =1, prob =0.5)
# if coin is heads add a common pattern to that row
if(coinFlip) {
dataMatrix[i, ] <- dataMatrix[i, ] + rep(c(0,3), each =5)
}}
hh <- hclust(dist(dataMatrix))
dataMatrixOrdered <- dataMatrix[hh$order, ]
image(t(dataMatrixOrdered)[, nrow(dataMatrixOrdered):1])
heatmap(t(dataMatrixOrdered)[, nrow(dataMatrixOrdered):1])
As far as I have understood, the only difference between the 2 functions is that, the heatmap()
function does a cluster analysis to produce dendrograms for rows and columns. Hence the plots should look the same. Can someone please tell me why I see this difference? I have attached the plots from the 2 functions.