怎樣在heatmap中使用多種cluster方法


生物信息學中經常使用R 來畫圖,而R畫heatmap的功能是非常強大的。通常,我的習慣是使用gplots包中的heatmap.2函數來進行畫圖。不過這個函數中不能對聚類分析(clustering)到方法進行調整,於是,小小寫一段代碼即能使用不同的聚類分析方法來對heatmap進行聚類整合。

 1 # There are 7 methods to make cluster in the function hclust in R
 2 Cluster_Method<-c( "ward", "single", "complete", "average", "mcquitty", "median", "centroid")
 3 
 4 for (i in 1:length(Cluster_Method)){
 5   #make a function to extract the cluster method
 6   myclust<-function(x){
 7     hclust(x,method=Cluster_Method[i])
 8   }
 9   #make heatmap by jpeg
10   jpeg(filename=paste(Cluster_Method[i],'.jpg'),width=1024,height=728)
11   heatmap.2(as.matrix(Data_Top1k_Var),
12             trace='none',
13             hclustfun=myclust,labRow=NA,
14             ColSideColors=c('black',grey(0.4),'lightgrey')[as.factor(CellLine_Anno$Type)],
15             xlab='CellLines',
16             ylab='Probes',
17             main=Cluster_Method[i],
18             col=greenred(64))
19   dev.off()
20 }

這樣就可以一下子把七種cluster的方法依次用到heatmap上面來。而且通過對cluster樹的比較,我們可以從中挑選出最好、最穩定到cluster方法,為后續分析打好基礎!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM