可视化R中的强连接组件

qsh*_*hng 3 r graph

我有一个带有三个强连通分量(SCC)的加权有向图.SCC是从该igraph::clusters功能获得的

library(igraph)
SCC<- clusters(graph, mode="strong")  
SCC$membership
 [1] 9 2 7 7 8 2 6 2 2 5 2 2 2 2 2 1 2 4 2 2 2 3 2 2 2 2 2 2 2 2
SCC$csize
[1]  1 21  1  1  1  1  2  1  1
 SCC$no
[1] 9
Run Code Online (Sandbox Code Playgroud)

我想用圆圈和彩色背景可视化SCC,如下图所示,有没有办法在R中做到这一点?谢谢!

在此输入图像描述

And*_*rau 11

看一下这个mark.groups论点plot.igraph.像下面这样的东西可以解决这个问题:

# Create some toy data
set.seed(1)
library(igraph)
graph <- erdos.renyi.game(20, 1/20)

# Do the clustering
SCC <- clusters(graph, mode="strong")  

# Add colours and use the mark.group argument
V(graph)$color <- rainbow(SCC$no)[SCC$membership]
plot(graph, mark.groups = split(1:vcount(graph), SCC$membership))
Run Code Online (Sandbox Code Playgroud)

Imgur