问题
I should find weak clusters and membership of the nodes in the clusters, and strong clusters and membership of the nodes in the clusters.
My code :
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)
As solution I got this :
> 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
But I didnt get which are my strong clusters, and i how can i plot my strong clusters in different color? Is there any good tutorial for R studio , coz there are no many sources for R studio?
回答1:
The clusters are in the membership part of clusters(g, mode="strong")
set.seed(247)
library(igraph)
g <- erdos.renyi.game(8, 15/100)
They are in the order of your nodes in the graph e.g.
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
To colour these in your plot do something like:
strongclusters <- clusters(g, mode="strong")$membership
plot(g, vertex.color = strongclusters)
来源:https://stackoverflow.com/questions/20725411/finding-strong-and-weak-clusters-and-their-membership-in-r