简体   繁体   English

R heatmap.2(图)访问树状图数据

[英]R heatmap.2 (gplots) access dendogram data

In RI use heatmap.2 (from the gplots package) to cluster and visualize some data. 在RI中,使用heatmap.2(来自gplots包)对数据进行聚类和可视化。

I would like to access the column dendrogram (clusters) for further manipulation of my data. 我想访问列树状图(群集)以进一步处理我的数据。

For example: 例如:

x = matrix(runif(250), nrow= 50) h = heatmap.2(x)

h$colDendrogram 
'dendrogram' with 2 branches and 5 members total, at height 3.033438

Is there a way to know the indexes of the column belonging to the first branch and those belonging to the second (in an automatic fashion ; of course in this simple case I might just look at labels on the x axis). 有没有一种方法可以知道属于第一个分支的列的索引和属于第二个分支的列的索引(以自动方式;当然,在这种简单情况下,我可能只看x轴上的标签)。

Further how can I access the other sub branches? 此外,我如何访问其他子分支?

One can use the as.hclust() function and treat the resulting object as if it were an R hclust object. 可以使用as.hclust()函数并将生成的对象视为R hclust对象。

For the specific case presented in the question this is how one access the column dendrogram: 对于问题中提出的特定情况,这是如何访问列树状图:

colhclust = as.hclust(h$colDendrogram)
groups = cutree(cl,2)

groups is a vector containing the group of each column; groups是包含每个列的组的向量;

id_g1 = which(groups == 1)

contains the indexes of items belonging to the first branch. 包含属于第一个分支的项目的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM