在R中,是否有与heatmap()类似的函数来可视化大型矩阵中的组? [英] In R, is there a similar function to heatmap() to visualize groups in a large matrix?

查看:114
本文介绍了在R中,是否有与heatmap()类似的函数来可视化大型矩阵中的组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在R中有一个1000 by 1000矩阵.矩阵中有100个组/社区,我希望以某种方式验证这100个组是否正在出现.例如,前10列/行定义一个组,后10列/行定义另一个组,依此类推.

I currently have a 1000 by 1000 matrix in R. There are 100 groups/communities in the matrix, and I wish to somehow verify if these 100 groups are appearing. For example, the first 10 columns/rows define a group, with the second 10 columns/rows defining another group, and so forth.

有没有一种方法可以直观地看到这样的分组?理想情况下,我将具有一个热图,该热图可以显示10 by 10的对角线块.我尝试了heatmap函数,但似乎没有做到这一点.

Is there a way in which I can visualize such a grouping is actually there? Ideally, I would have a heatmap that can show diagonal blocks of 10 by 10. I tried the heatmap function but it doesn't appear to do that.

有人在这里有什么想法吗?

Does anyone have any ideas here?

推荐答案

我不确定为什么您说heatmap似乎没有这样做".它似乎为我工作.我假设您的矩阵是邻接矩阵.我提供了一个非常简单的示例,其中有10个节点的100个高度连接的组,但组之间的连接很少.

I am not sure why you say that heatmap "doesn't appear to do that". It seems to work for me. I assume that your matrix is an adjacency matrix. I provide a very simple example where there are 100 highly connected groups of 10 nodes, but there are few connections between the groups.

样本数据

## First generate the graph
set.seed(1234)
GX = erdos.renyi.game(10,0.8)
for(i in 1:99) {
    GX = GX + erdos.renyi.game(10,0.8) }

for(i in 0:99) {
    rv = sample(10,2)
    GX = add.edges(GX, c(i*10+rv[1], ((i+1)*10+rv[2]) %% 1000)) } 

## Now we need the adjacency matrix
AM = as.matrix(as_adjacency_matrix(GX))

我将以两种方式绘制此矩阵.首先,将其绘制出来.

I am going to plot this matrix two ways. First, just plot it.

heatmap(AM, Rowv=NA, Colv=NA, col=terrain.colors(16),
    labRow=FALSE, labCol=FALSE, revC=TRUE)

这是应该做的,但是试图将 无法将2000 x 1000的计算机屏幕上的1000 x 1000图像 很好.尽管各组在对角线的下方, 看到这么大的东西是很难的.相反,让我们 只需查看左上100 x 100的部分(前10组) 增加尺寸.

This is doing what it is supposed to do, But trying to put a 1000 x 1000 image onto a 2000 x 1000 computer screen can't come out very well. Although the groups are there down the diagonal, it is very difficult to see anything at this size. Instead, let's just view the upper left 100 x 100 part (first 10 groups) to increase the size.

heatmap(AM[1:100, 1:100], Rowv=NA, Colv=NA, col=terrain.colors(16),
    labRow=FALSE, labCol=FALSE, revC=TRUE)

很容易看到10个高度连接的10个组,只是组之间的连接提示.

It is easy to see the 10 highly connected groups of 10 and just a hint of connection between the groups.

要查看具有如此大矩阵的任何内容,您需要将其放大.

To see anything with such a large matrix, you will need to magnify.

这篇关于在R中,是否有与heatmap()类似的函数来可视化大型矩阵中的组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆