聚类热图的层级关系是固定的,但分支的左右镜像是可变的。如何让聚类结果更好的呈现我们想要的顺序呢?看下面的操作。
exprTable <- read.table("exprTable.txt", sep=" ", row.names=1, header=T, check.names = F)
exprTable
测试时直接拷贝这个数据即可
## Zygote 2_cell 4_cell 8_cell Morula ICM
## Pou5f1 1.0 2.0 4.0 8.0 16.0 32.0
## Sox2 0.5 1.0 2.0 4.0 8.0 16.0
## Gata2 0.3 0.6 1.3 2.6 5.2 10.4
## cMyc 10.4 5.2 2.6 1.3 0.6 0.3
## Tet1 16.0 8.0 4.0 2.0 1.0 0.5
## Tet3 32.0 16.0 8.0 4.0 2.0 1.0
library(pheatmap)
pheatmap(exprTable)
自己做个hclust传进去,顺序跟pheatmap默认是一样的
exprTable_t <- as.data.frame(t(exprTable))
col_dist = dist(exprTable_t)
hclust_1 <- hclust(col_dist)
pheatmap(exprTable, cluster_cols = hclust_1)
按发育时间排序样品
manual_order = c("Zygote", "2_cell", "4_cell", "8_cell", "Morula", "ICM")
dend = reorder(as.dendrogram(hclust_1), wts=order(match(manual_order, rownames(exprTable_t))))
# 默认为mean,无效时使用其他函数尝试
# dend = reorder(as.dendrogram(hclust_1), wts=order(match(manual_order, rownames(exprTable_t))), agglo.FUN = max)
col_cluster <- as.hclust(dend)
pheatmap(exprTable, cluster_cols = col_cluster)
可以按任意指标排序,基因表达是一个例子。
dend = reorder(as.dendrogram(hclust_1), wts=exprTable_t$Tet3)
col_cluster <- as.hclust(dend)
pheatmap(exprTable, cluster_cols = col_cluster)
dend = reorder(as.dendrogram(hclust_1), wts=exprTable_t$Tet3*(-1))
col_cluster <- as.hclust(dend)
pheatmap(exprTable, cluster_cols = col_cluster)
library(dendextend)
col_cluster <- hclust_1 %>% as.dendrogram %>% sort %>% as.hclust
pheatmap(exprTable, cluster_cols = col_cluster)
col_cluster <- hclust_1 %>% as.dendrogram %>% ladderize(TRUE) %>% as.hclust
pheatmap(exprTable, cluster_cols = col_cluster)
col_cluster <- hclust_1 %>% as.dendrogram %>% ladderize(FALSE) %>% as.hclust
pheatmap(exprTable, cluster_cols = col_cluster)
样本量多时的自动较忧排序
sv = svd(exprTable)$v[,1]
dend = reorder(as.dendrogram(hclust_1), wts=sv)
col_cluster <- as.hclust(dend)
pheatmap(exprTable, cluster_cols = col_cluster)
R语言学习 - 热图美化 (数值标准化和调整坐标轴顺序)
图形解读系列 | 给你5个示例,你能看懂常用热图使用吗?
ComplexHeatmap |理解绘图逻辑绘制热图
获取pheatmap聚类后和标准化后的结果
这也太简单了吧!一个函数完成数据相关性热图计算和展示
https://stackoverflow.com/questions/52446477/r-hclust-common-order-for-multiple-trees
https://www.biostars.org/p/237067/
留言与评论(共有 0 条评论) “” |