How to visualize a large network in R?

后端 未结 5 1755
长发绾君心
长发绾君心 2020-12-07 07:50

Network visualizations become common in science in practice. But as networks are increasing in size, common visualizations become less useful. There are simply too many node

5条回答
  •  盖世英雄少女心
    2020-12-07 08:05

    I've been dealing with this problem recently. As a result, I've come up with another solution. Collapse the graph by communities/clusters. This approach is similar to the third option outlined by the OP above. As a word of warning, this approach will work best with undirected graphs. For example:

    library(igraph)
    
    set.seed(123)
    g <- barabasi.game(1000) %>%
      as.undirected()
    
    #Choose your favorite algorithm to find communities.  The algorithm below is great for large networks but only works with undirected graphs
    c_g <- fastgreedy.community(g)
    
    #Collapse the graph by communities.  This insight is due to this post http://stackoverflow.com/questions/35000554/collapsing-graph-by-clusters-in-igraph/35000823#35000823
    
    res_g <- simplify(contract(g, membership(c_g))) 
    

    The result of this process is the below figure, where the vertices' names represent community membership.

    plot(g, margin = -.5)
    

    The above is clearly nicer than this hideous mess

    plot(r_g, margin = -.5)
    

    To link communities to original vertices you will need something akin to the following

    mem <- data.frame(vertices = 1:vcount(g), memeber = as.numeric(membership(c_g)))
    

    IMO this is a nice approach for two reasons. First, it can in theory deal with any size graph. The process of finding communities can be continuously repeated on collapsed graphs. Second, adopting a interactive approach would yield very readable results. For example, one can imagine the user being able to click on a vertex in the collapsed graph to expand that community revealing all of its original vertices.

提交回复
热议问题