방문자
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
블로그 내부검색
주제
연재
한 주 BEST
- [© 최광민] 예수 vs. 예수 #07: 삼위일체 개념은 어디서 유래했을까?
- [© 최광민] 예수 vs. 짜라투스투라 #01: 기독교의 예수는 짜라투스트라를 표절했을까?
- [© 최광민] 예수 vs. 붓다 #1: 소위 "불교계통" 복음서들의 정체: {이사전}, {보병궁 복음서}, {유란시아書}, {임마누엘의 탈무드}
- [© 최광민] 랍비 카두리의 메시아, 예수
- [© 최광민] 예수 vs. 예수 #11: 크리스마스의 기원과 동방박사의 별 (합본)
- [© 최광민] 예수 vs. 예수 #02: 예수는 언제부터 신이었을까?
- [© 최광민] 불문학자 민희식 vs. 불교작가 민희식 | 제 1부: 한국이 낳은 어떤 "세계적(?)" 석학?
- [© 최광민] 전쟁에 관한 기독교 초기교부들의 견해
- [© 최광민] 아멘 vs. 아멘: 유대교/기독교의 '아멘'은 이집트신 '아멘'에서 유래했을까?
- [© 최광민] 로마카톨릭 vs. 프로테스탄트 #03: 예정과 자유의지, 그리고 구원
최신 포스팅
heatmap, hclust, dendrogram
Labels:
Informatics
이메일로 전송BlogThis!X에 공유Facebook에서 공유
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)
이메일로 전송BlogThis!X에 공유Facebook에서 공유
Labels:
Informatics
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
[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


