Could someone explain how communities are determined based on R’s cluster_edge_betweenness function? I would like to know why, in the attached graph, p14 and p15 are grouped with the g6 community and not with the other one (g3 + g5). And how can I force these two nodes to be clustered with g3/g5? I tried using ‘weights’ but no luck.
library(igraph)
library(dplyr)
mydf <- data.frame(id=LETTERS, locus=c(rep("alpha",14), rep("beta",12)),
group=c(rep(1,2), rep(2,6), rep(3,6), rep(4,4), rep(5,4), rep(6,4)),
pair=c(1:12,14,15,3,4,6,8,9:16))
mydf <- filter(mydf, group %in% c(3,5,6))
mydf
g <- mydf %>%
dplyr::mutate(sg = paste0("g", group), sp = paste0("p", pair)) %>%
dplyr::select(sg, sp, locus) %>%
graph_from_data_frame(directed=FALSE)
g
#IGRAPH f429061 UN-- 11 14 --
#+ attr: name (v/c), locus (e/c)
#+ edges from f429061 (vertex names):
# [1] g3--p9 g3--p10 g3--p11 g3--p12 g3--p14 g3--p15 g5--p9 g5--p10 g5--p11 g5--p12 g6--p13
#[12] g6--p14 g6--p15 g6--p16
ceb <- cluster_edge_betweenness(g)
plot(ceb, g,
vertex.shape=c(rep("square",3), rep("circle",8)),
col="yellow",
edge.color = as.factor(E(ig)$locus),
edge.width=2 + (E(ig)$locus=="alpha") * 2)