in igraph
, after applying modularization algorithm find graph communites, draw network layout makes visible distinct communities , connections. "group attributes layout" in cytoscape: want show members of each group/community close each other, , keep distance between groups/communities. couldn't find function in igraph
providing feature out of box. while posting question have found out simple d.i.y solution, going post answer. wondering if there better possibility, or more elaborated solution?
to expand on gabor's suggestion, have created function:
weight.community=function(row,membership,weigth.within,weight.between){ if(as.numeric(membership[which(names(membership)==row[1])])==as.numeric(membership[which(names(membership)==row[2])])){ weight=weigth.within }else{ weight=weight.between } return(weight) }
simply apply on rows of matrix of edges of graph (given get.edgelist(your_graph))
set new edge weights (membership membership vector result of community detection algorithm):
e(g)$weight=apply(get.edgelist(g),1,weight.community,membership,10,1)
then, use layout algorithm accepts edge weights such fruchterman.reingold suggested gabor. can tweak weights arguments obtain graph want. instance:
e(g)$weight=apply(get.edgelist(g),1,weight.community,membership,10,1) g$layout=layout.fruchterman.reingold(g,weights=e(g)$weight) plot(g)
e(g)$weight=apply(get.edgelist(g),1,weight.community,membership,1000,1) g$layout=layout.fruchterman.reingold(g,weights=e(g)$weight) plot(g)
note 1: transparency/colors of edges other parameters of graphs. have colored nodes community shows indeed works.
note 2: make sure use membership(comm)
, not comm$membership
, comm
result of community detection algorithm (e.g., comm=leading.eigenvector.community(g)
). reason in first case, numeric vector names (what want), , in second case, same vector without names.
to consensus of multiple community detection algorithms, see function.
Comments
Post a Comment