我想在 R 中的二进制矩阵上应用 byclustering。有一个名为“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)
我应用了“biclust”R包的biclust函数:
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)
到目前为止一切顺利,但我想要:
这些更改是否可能(使用“biclust”包)?还是用 R 以另一种方式做更好?
最佳答案
更改 biclust 源包中的 drawHeatmap() 函数:
(a) 切换红色和绿色 - 在调用 rgb() 中切换 rvect 和 gvect
(b) 原始行名而不是新行 - 将 'labels=' 更改为 '=bicCols' 和 '=bicRows'。
关于r - R中的双聚类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38497520/