我有一个问题,关于放大我的数据集中找到的集群。我想创建与返回时给定数量的集群一样多的新矩阵。具体来说,我不确定如何返回数据并剔除感兴趣的子群体。我知道我可以做到:
mycl <- cutree(hr, 2);
但是然后呢?
这是我到目前为止所拥有的[完整代码]:
假设您有一个矩阵“m”,您通过相关矩阵中的距离按行“hr”和列“hc”进行聚类
m = matrix(0, 10, 5, dimnames = list(c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J"), c(1, 2, 3, 4, 5)))
m[1,] = c(0,0,0,0,1)
m[2,] = c(0,0,0,1,1)
m[3,] = c(0,0,1,1,1)
m[4,] = c(0,0,1,1,0)
m[5,] = c(1,0,0,0,0)
m[6,] = c(1,1,1,0,0)
m[7,] = c(0,1,1,0,0)
m[8,] = c(0,1,1,0,0)
m[9,] = c(0,1,1,1,0)
m[10,] = c(1,1,1,0,1)
# Generates row and column dendrograms.
hr <- hclust(as.dist(1-cor(t(m), method="pearson")), method="ward");
hc <- hclust(as.dist(1-cor(m, method="spearman")), method="ward")
现在,我可以对我的数据进行热图:
library(gplots)
mycl <- cutree(hr, 2);
mycolhc <- rainbow(length(unique(mycl)), start=0.1, end=0.9);
mycolhc <- mycolhc[as.vector(mycl)]
myheatcol <- redgreen(75)
# Creates heatmap for entire data set
heatmap.2(
m,
Rowv=as.dendrogram(hr),
Colv=as.dendrogram(hc),
col=myheatcol,
scale="row",
density.info="none",
trace="none",
RowSideColors=mycolhc,
cexCol=0.6,
labRow=NA
)