我想在R中的二进制矩阵上应用聚类。有一个很好的包叫做#34; biclust"可用,但它确实并且不显示我想要的所有内容。
我有一个二进制矩阵,如下所示:
1 0 0 1 0 1 0
0 0 0 0 0 0 0
0 0 1 0 1 0 0
1 0 0 1 0 1 0
0 0 1 0 1 0 0
1 0 0 1 0 1 0
0 0 0 0 0 0 0
我的目标是将以下(可能是彩色的)双重(并显示):
1 1 1 0 0 0 0
1 1 1 0 0 0 0
1 1 1 0 0 0 0
0 0 0 1 1 0 0
0 0 0 1 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
设置代码:
# install.packages("biclust") (if necessary)
library("biclust")
testMatrix <- matrix(c(1,0,0,1,0,1,0,
0,0,0,0,0,0,0,
0,0,1,0,1,0,0,
1,0,0,1,0,1,0,
0,0,1,0,1,0,0,
1,0,0,1,0,1,0,
0,0,0,0,0,0,0),
nrow = 7,
ncol = 7,
byrow = TRUE)
我应用了&#34; biclust&#34;的双重功能。 R包:
testCluster <- biclust(x = testMatrix, method=BCBimax())
确实我得到了两个预期的集群:
An object of class Biclust
call:
biclust(x = testMatrix, method = BCBimax())
Number of Clusters found: 2
First 2 Cluster sizes:
BC 1 BC 2
Number of Rows: 3 2
Number of Columns: 3 2
我可以通过以下方式单独显示群集:
drawHeatmap(x = testMatrix, bicResult = testCluster, number = 1) # shown in picture below
drawHeatmap(x = testMatrix, bicResult = testCluster, number = 2)
我可以通过以下方式显示整个聚类矩阵(左上角的一个聚类):
drawHeatmap2(x = testMatrix, bicResult = testCluster, number = 1) # shown in picture below
drawHeatmap2(x = testMatrix, bicResult = testCluster, number = 2)
到目前为止一切顺利,但我想:
这些更改是否可行(使用&#34; biclust&#34;包)?或者用R做另外一种方式更好吗?
答案 0 :(得分:3)
更改biclust source packag包中的drawHeatmap()函数: