I have created a graph and used the propagating labels community detection algorithm to detect subgroups in the graph. I have then plotted the graph and coloured the vertices according to their group membership using rainbow colours. Here is the code I used:
g <- watts.strogatz.game(1, 100, 5, 0.05)
clp <- cluster_label_prop(g)
V(g)$community <- clp$membership
rain <- rainbow(14, alpha=.5)
V(g)$color <- rain[V(g)$community]
plot(g, vertex.size=4, vertex.label=NA)
I would now like to colour edges that lie between members of a subgroup in the same colour as that subgroup, in order to better highlight the within-group ties. I would like to leave the between-group ties grey. I cannot work out how to do it, help would be greatly appreciated.
Thanks
The following should work:
library(igraph)
g <- watts.strogatz.game(1, 100, 5, 0.05)
clp <- cluster_label_prop(g)
V(g)$community <- clp$membership
rain <- rainbow(14, alpha=.5)
V(g)$color <- rain[V(g)$community]
E(g)$color <- apply(as.data.frame(get.edgelist(g)), 1,
function(x) ifelse(V(g)$community[x[1]] == V(g)$community[x[2]],
rain[V(g)$community[x[1]]], '#00000000'))
plot(g, vertex.size=4, vertex.label=NA, edge.color=E(g)$color)
来源:https://stackoverflow.com/questions/41912732/how-to-colour-edges-within-community-clusters-in-igraph
