Reputation: 4869
I have a graph from which I extract communities using Louvain-Algorithm implementation:
clusters = g.community_multilevel( weights=None, return_levels=False)
I then apply different colouring for each community:
new_cmap = ['#'+''.join([random.choice('0123456789abcdef') for x in range(6)]) for z in range(len(clusters))]
colors = {v: new_cmap[i] for i, c in enumerate(clusters) for v in c}
g.vs["color"] = [colors[e] for e in g.vs.indices]
Finally I plot the graph:
visual_style["layout"] = g.layout_fruchterman_reingold(weights=g.es["weight"], maxiter=1000, area=N ** 3, repulserad=N ** 3)
igraph.plot(g, **visual_style)
My question is :
Instead of this mixed-up graph, is there a way using a specific Layout, to plot every of the four community grouped by itself? I would like to separate every community in a different area of the graph increasing the visibility of their inner structure as well as the few edges with higher betweenness-centrality connecting the communities?
I have used the contract-vertices
function that helped me to visualise, but is an oversimplification that just group every community in a single point and doesn't allow to visualise the inner structure of each community. Am I using 'contract-vertices' in the best way?
Thanks.
Upvotes: 1
Views: 1978
Reputation: 4869
I found the solution being to drastically increase weight of edges which belong to the community (3 times the number of vertices in the below example):
clusters = g.community_multilevel( weights=None, return_levels=False)
member = clusters.membership
new_cmap = ['#'+''.join([random.choice('0123456789abcdef') for x in range(6)]) for z in range(len(clusters))]
vcolors = {v: new_cmap[i] for i, c in enumerate(clusters) for v in c}
g.vs["color"] = [vcolors[v] for v in g.vs.indices]
ecolors = {e.index: new_cmap[member[e.tuple[0]]] if member[e.tuple[0]]==member[e.tuple[1]] else "#e0e0e0" for e in g.es}
eweights = {e.index: (3*g.vcount()) if member[e.tuple[0]]==member[e.tuple[1]] else 0.1 for e in g.es}
g.es["weight"] = [eweights[e.index] for e in g.es]
g.es["color"] = [ecolors[e] for e in g.es.indices]
visual_style["layout"] = g.layout_fruchterman_reingold(weights=g.es["weight"], maxiter=500, area=N ** 3, repulserad=N ** 3)
igraph.plot(g, **visual_style)
I assume the need for 'drastically increase' edges weight within communities is due to the fact that my graph is composed of some vertices that represent less than 2% of the number of vertices but have more than 80% of edges connected to them even though they belong to different communities. In the below graph the many edges outside communities are in light grey:
Upvotes: 2