3

I have a weighted directed graph with three strongly connected components(SCC). The SCCs are obtained from the igraph::clusters function

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

I want to visualize the SCCs with circles and a colored background as the graph below, is there any ways to do this in R? Thanks!

enter image description here

qshng
  • 887
  • 1
  • 13
  • 32
  • 1
    To provide you with a real answer, we would need your data and a minimal working example. See also here: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – TARehman May 07 '15 at 15:26
  • Have you taken a look at the argument `mark.groups` of the `igraph` plotting function: `?plot.igraph`? – Vincent Guillemot May 07 '15 at 15:28

1 Answers1

11

Take a look at the mark.groups argument of plot.igraph. Something like the following will do the trick:

# 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))

Imgur

Anders Ellern Bilgrau
  • 9,928
  • 1
  • 30
  • 37