我应该找到集群中节点的弱集群和成员资格,以及集群中强节点和节点成员资格.
我的代码:
library(igraph)
g <- erdos.renyi.game(8, 15/100)
is.connected(g, mode=("strong"))
clusters(g, mode="strong")
no.clusters(g, mode="strong")
cluster.distribution(g, cumulative = FALSE, mul.size = FALSE)
Run Code Online (Sandbox Code Playgroud)
作为解决方案,我得到了:
> library(igraph)
> g <- erdos.renyi.game(8, 15/100)
> is.connected(g, mode=("strong"))
[1] FALSE
> clusters(g, mode="strong")
$membership
[1] 1 2 1 1 3 1 4 1
$csize
[1] 5 1 1 1
$no
[1] 4
> no.clusters(g, mode="strong")
[1] 4
> cluster.distribution(g, cumulative = FALSE, mul.size = FALSE)
[1] 0.00 0.75 0.00 0.00 0.00 0.25
Run Code Online (Sandbox Code Playgroud)
但我没有得到哪些是我强大的星团,我怎么能用不同的颜色绘制我强壮的星团呢?R studio是否有任何好的教程,因为R studio没有多少资源?
集群membership属于clusters(g, mode="strong")
set.seed(247)
library(igraph)
g <- erdos.renyi.game(8, 15/100)
Run Code Online (Sandbox Code Playgroud)
它们按图中节点的顺序排列,例如
V(g) # the nodes in your graph are 1-8
#Vertex sequence:
#[1] 1 2 3 4 5 6 7 8
# the respective cluster for nodes 1-8 are:
clusters(g, mode="strong")$membership
#[1] 1 2 3 1 1 4 5 2
Run Code Online (Sandbox Code Playgroud)
要在你的情节中对这些颜色进行着色,请执
strongclusters <- clusters(g, mode="strong")$membership
plot(g, vertex.color = strongclusters)
Run Code Online (Sandbox Code Playgroud)
