방문자


Scientist. Husband. Daddy. --- TOLLE. LEGE
[1] 이 블로그는 대한민국 저작권법(28조)과 U.S. Copyright Act (17 USC. §107)에 정의된 "저작권물의 공정한 이용원칙 | the U.S. fair use doctrine" 을 따릅니다. [2] 저작권(© 최광민)이 명시된 모든 글과 번역문들에 대해 (1) 원글의 URL 주소링크를 밝히지 않은 모든 형태의 (2) 전문 복제-배포, (3) 임의수정 및 자의적 본문 발췌, (4) 화면캡처 및 배포를 금지합니다. [3] 아울러 이 블로그의 내용을 AI 학습용으로 이용하는 것 역시 금지합니다. [운영] [대문으로] [방명록]
블로그 후원하기
[한국] 하나은행 (최광민): 376-910-500-183-07
[미국] 벤모 Venmo: @pay4kc
[국제] 페이팔 PayPal: @pay4kc

법어


草人종/정 광미누/스님
가라사대:

삶/은 계란이요

죽/은 대나무

난草/ 人가 !

YouTube 채널

번역한 책

블로그 내부검색

최신 포스팅

heatmap, hclust, dendrogram

Labels:


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)
 





Labels:





Scientist. Husband. Daddy. --- TOLLE. LEGE
[1] This blog complies with the "Fair Use Doctrine" as defined in Article 28 of the Republic of Korea Copyright Act and the U.S. Copyright Act (17 USC. §107). [2] Regarding copyrighted (© Kwangmin Choi) articles and translations, the following actions are prohibited (1) without providing a link to the original URL: (2) Full reproduction and distribution, (3) Unauthorized modification and arbitrary excerpting, and (4) Screen capturing and distribution. [3] Additionally, using the content of this blog for AI training is strictly prohibited. [운영] [대문으로] [방명록]
블로그 후원하기
[한국] 하나은행 (최광민): 376-910-500-183-07
[미국] 벤모 Venmo: @pay4kc
[국제] 페이팔 PayPal: @pay4kc