I am trying to get a plot generated via heatmap.2, but would like to understand how the clustering is done. So, I tried to replicate the dendograms ahead of the function call, and plot with these. However, the final figures are different. any clue?
HEATMAP 1:
h<-heatmap.2(dat,col=redgreen, trace="none",
xlab="Samples", ylab="Genes" ,scale="none" )
vs.
HEATMAP 2:
Rowv <- hclust( dist(dat)) #defaults to method="euclidean" and method="complete")
Colv <- hclust(dist(t(dat))) #same as above
heatmap.2(dat, Rowv=as.dendrogram(Rowv), Colv=as.dendrogram(Colv),
col=redgreen, trace="none",
xlab="Samples", ylab="Genes",scale="none" )
These two would generate different heatmaps. Any clue why?
Try
Rowv <- as.dendrogram(hclust(dist(X)))
Maybe as.dendrogram
makes the difference here. R is still a mess^W^W a mystery to me.
I'm pretty late but I'll try. I don't know about heatmap.2
, but heatmap reorders the dendrogram by default.
To get exactly the same results as those you get when not providing the precalculated dendrogram you would have to say (for the row dendrogram):
Rowv <- hclust( dist(dat))
Rowv <- reorder(as.dendrogram(Rowv), rowMeans(dat)) # reorder by the row means of dat <br/>
heatmap(dat, Rowv=Rowv, Colv=Colv=as.dendrogram(Colv),col=redgreen, trace="none",xlab="Samples", ylab="Genes",scale="none" )
# leaving everything else as in your original message
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.