在R中,我使用heatmap.2(来自gplots包)来聚类并可视化一些数据。
我想访问列树形图(簇)以进一步操作我的数据。
例如:
x = matrix(runif(250), nrow= 50) h = heatmap.2(x)
h$colDendrogram
'dendrogram' with 2 branches and 5 members total, at height 3.033438
有没有办法知道属于第一个分支的列的索引 和那些属于第二个(以自动方式;当然在这个简单 case我可能只看x轴上的标签。)
此外,我如何访问其他子分支?
答案 0 :(得分:1)
可以使用as.hclust()函数将结果对象视为R hclust对象。
对于问题中提供的具体情况,这是如何访问列树形图:
colhclust = as.hclust(h$colDendrogram)
groups = cutree(cl,2)
groups是包含每列的组的向量;
id_g1 = which(groups == 1)
包含属于第一个分支的项目的索引。