我想在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源packag包中更改drawHeatmap()函数:
(a)切换红色和绿色-在调用rgb()中切换rvect和gvect
(b)原始行名代替新行名-将'labels ='更改为'= bicCols'和'= bicRows'。
关于r - R中的丛集,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38497520/