我应该找到集群中节点的弱集群和成员资格,以及集群中强节点和节点成员资格。
我的代码:
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)
作为解决方案,我得到了这个:
> 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
但我没有得到哪些是我强大的星团,我怎么能用不同的颜色绘制我强壮的星团呢? R studio是否有任何好的教程,因为R studio没有多少资源?
答案 0 :(得分:6)
群集位于membership
clusters(g, mode="strong")
部分
set.seed(247)
library(igraph)
g <- erdos.renyi.game(8, 15/100)
它们按图中节点的顺序排列,例如
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
要在你的情节中为这些颜色着色,请执行以下操作:
strongclusters <- clusters(g, mode="strong")$membership
plot(g, vertex.color = strongclusters)