[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[igraph] How to plot graph and adjusted community detection (R)?
From: |
MikeS |
Subject: |
[igraph] How to plot graph and adjusted community detection (R)? |
Date: |
Sat, 9 Jan 2016 21:41:33 +0600 |
Hello to all,
I would like to correct given community detection and plot the origin
graph g2 and new community detection together.
library(igraph)
set.seed(42)
g2 <- erdos.renyi.game(20, 72, type="gnm", directed=TRUE)
comm <- optimal.community(g2)
modularity(comm, g2)
#[1] 0.2573302
comm
#IGRAPH clustering optimal, groups: 3, mod: 0.26
#+ groups:
# $`1`
#[1] 1 2 3 7 8 13
# $`2`
# [1] 4 6 9 10 12 15 16 17 20
#
# $`3`
# [1] 5 11 14 18 19
The 20 nodes were split into three communities. I wrote the numbers of
communities to the vector commajd, then compute the function
modularity() again. Btw, results are different: 0.2573302 - 0.25 =
0.0073302, may be I made an error in vector.
commajd <- c(1, 1, 1, 2, 3, 2, 1, 1, 2, 2, 3, 2, 1, 3, 2, 2, 2, 3, 3, 2)
modularity(g2, commajd)
#[1] 0.25
I would like to move, for example, the first node from comm[1] to
comm[2] and compute the function modularity(). Result is below:
commajd <- c(2, 1, 1, 2, 3, 2, 1, 1, 2, 2, 3, 2, 1, 3, 2, 2, 2, 3, 3, 2)
modularity(g2, commajd)
#[1] 0.2371721
Could someone please say me how to plot the origin graph g and new
community detection commajd together?
I tried
plot(commajd, g2)
# Error in xy.coords(x, y, xlabel, ylabel, log) :
# 'x' and 'y' lengths differ
In my example commajd is the vector, not a community object.
Many thanks.
- [igraph] How to plot graph and adjusted community detection (R)?,
MikeS <=