How to split an igraph into connected subgraphs?

前端 未结 1 328
花落未央
花落未央 2020-12-02 23:05

I have an igraph with several disconnected components. For example:

library(igraph)
g <- simplify(
  graph.compose(
    graph.ring(10), 
    graph.star(5         


        
相关标签:
1条回答
  • 2020-12-02 23:55

    You could calculate the connected components of your graph by using:

    clusters(g)
    # $membership
    # [1] 1 1 1 1 1 1 2 2 3 1
    # 
    # $csize
    # [1] 7 2 1
    # 
    # $no
    # [1] 3
    

    Or you could create a separate graph for each component of your graph by using:

    dg <- decompose.graph(g) # returns a list of three graphs
    plot(dg[[1]]) # plot e.g. the 1st one
    

    enter image description here

    0 讨论(0)
提交回复
热议问题