如何在igraph中为社区集群中的边缘着色 [英] How to colour edges within community clusters in igraph

查看:119
本文介绍了如何在igraph中为社区集群中的边缘着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个图形,并使用了传播标签社区检测算法来检测图形中的子组.然后,我绘制了图形,并根据它们的组成员资格使用彩虹色为顶点着色.这是我使用的代码:

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.

谢谢

推荐答案

以下方法应该起作用:

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)

这篇关于如何在igraph中为社区集群中的边缘着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆