-->

GoogleSearch



추천영상: 12인치 천체망원경으로 촬영한 토성

Scientist. Husband. Daddy. --- TOLLE. LEGE
외부자료의 인용에 있어 대한민국 저작권법(28조)과 U.S. Copyright Act (17 USC. §107)에 정의된 "저작권물의 공정한 이용원칙 | the U.S. fair use doctrine" 을 따릅니다. 저작권(© 최광민)이 명시된 모든 글과 번역문들에 대해 (1) 복제-배포, (2) 임의수정 및 자의적 본문 발췌, (3) 무단배포를 위한 화면캡처를 금하며, (4) 인용 시 URL 주소 만을 사용할 수 있습니다. [후원 | 운영] [대문으로] [방명록] [옛 방명록] [티스토리 (백업)]

이 블로그 검색

heatmap, hclust, dendrogram

라벨:


tricks

# Generate a sample matrix
y <- matrix(rnorm(50), 10, 5, dimnames=list(paste("g", 1:10, sep=""),
paste("t", 1:5, sep=""))) 

# Cluster rows and columns by correlation distance
hr <- hclust(as.dist(1-cor(t(y), method="pearson"))) 
hc <- hclust(as.dist(1-cor(y, method="spearman"))) 

# Obtain discrete clusters with cutree
mycl <- cutree(hr, h=max(hr$height)/1.5)

# Prints the row labels in the order they appear in the tree.
hr$labels[hr$order] .
# Prints the row labels and cluster assignments
sort(mycl) 

# Some color selection steps
mycolhc <- sample(rainbow(256))
mycolhc <- mycolhc[as.vector(mycl)]

# Plot the data matrix as heatmap and the cluster results as dendrograms
with heatmap or heatmap.2
# and show the cutree() results in color bar.
heatmap(y, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc), scale="row",
RowSideColors=mycolhc) 
 
 
library("gplots") 
heatmap.2(y, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc),
col=redgreen(75), scale="row", 
ColSideColors=heat.colors(length(hc$labels)), RowSideColors=mycolhc,
trace="none", key=T, cellnote=round(t(scale(t(y))),1))
 
 
 
# 2  
 
 
data        <- data.matrix(data)
data <- y 
distance    <- dist(data)
cluster     <- hclust(distance, method="ward")
dendrogram  <- as.dendrogram(cluster)
Rowv        <- rowMeans(data, na.rm = T)
dendrogram  <- reorder(dendrogram, Rowv)
## Produce the heatmap from the calculated dendrogram.
## Don't allow it to re-order rows because we have already re-ordered them above.

reorderfun = function(d,w) { d }
png("heatmap.png", res=150, height=22,width=17,units="in")

heatmap(data,col=colors,breaks=breaks,scale="none",Colv=NA,Rowv=dendrogram,labRow=NA, reorderfun=reorderfun)

dev.off()

## Re-order the original data using the computed dendrogram
rowInd = rev(order.dendrogram(dendrogram))
di = dim(data)
nc = di[2L]
nr = di[1L]
colInd = 1L:nc
data_ordered <- data[rowInd, colInd]
write.table(data_ordered, "rows.txt",quote=F, sep="\t",row.names=T, col.names=T)
 





라벨:





Scientist. Husband. Daddy. --- TOLLE. LEGE
외부자료의 인용에 있어 대한민국 저작권법(28조)과 U.S. Copyright Act (17 USC. §107)에 정의된 "저작권물의 공정한 이용원칙 | the U.S. fair use doctrine" 을 따릅니다. 저작권(© 최광민)이 명시된 모든 글과 번역문들에 대해 (1) 복제-배포, (2) 임의수정 및 자의적 본문 발췌, (3) 무단배포를 위한 화면캡처를 금하며, (4) 인용 시 URL 주소 만을 사용할 수 있습니다. [후원 | 운영] [대문으로] [방명록] [옛 방명록] [티스토리 (백업)] [신시내티]

-