如何在R中仅绘制大型社区/集群 [英] How to plot only large communities/clusters in R

查看:40
本文介绍了如何在R中仅绘制大型社区/集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 g 中有一个igraph.由于该图非常庞大,因此我只想绘制具有超过 10 个成员的社区,但是我想将它们全部绘制在一个图中.我删除不必要元素的想法是:

I have an igraph in g. Since the graph is huge I only want to plot communities with more than 10 members, but I want to plot them all in one plot. My idea to remove unwanted elements is:

g <- delete_vertices(g, V(g)[igraph::clusters(g)$csize < 10])

但是由于某种原因,它绘制了很多单个节点,这与我尝试实现的相反.你能告诉我我哪里错了吗?

but for some reason this plots a lot of single nodes, which is the opposite of what I try to achieve. Can you tell me where I am wrong?

推荐答案

您的想法很棒,但问题是

Your idea is great, but the problem is that

igraph::clusters(g)$csize < 10

仅返回包含少于10个成员的群集的逻辑向量.同时,您需要知道哪些顶点属于这些簇.

only returns a logical vector of clusters containing fewer than 10 members. Meanwhile, you need to know which vertices belong to those clusters.

因此,我们可以按如下进行操作.

Hence, we may proceed as follows.

set.seed(1)
g1 <- erdos.renyi.game(100, 1 / 70)
cls <- clusters(g1)
cls$csize
#  [1]  1  1 43  2 11  1  1  1  2  1  2  5  1  1  4  4  1  1  1  1  2  1  2  1
# [25]  4  1  1  1  1  1 # Two clusters of interest
g2 <- delete_vertices(g1, V(g1)[cls$membership %in% which(cls$csize <= 10)])
plot(g2)

这篇关于如何在R中仅绘制大型社区/集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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