【问题标题】:How to subset a large igraph to just one node and its connected nodes using R?如何使用 R 将大型 igraph 子集化为一个节点及其连接的节点?
【发布时间】:2018-09-23 09:15:02
【问题描述】:

我在 R 中有一个非常大的 igraph(称为 g)。

我只对一个节点 (NodeA) 以及直接连接到 NodeA 的任何节点感兴趣。我想最终得到一个非常简单的图表,如下图所示。

我已经尝试过 subgraph(g, "nodeA") 但我最终只得到了 NodeA。

我认为我需要将图 g 的边子集化为连接到 nodeA 的边,然后使用 subgraph.edges()。我不知道如何根据连接到的节点对边缘进行子集化...

【问题讨论】:

    标签: r igraph


    【解决方案1】:

    尝试使用neighbors()

    # Example graph
    g1 <- graph_from_literal(1:2:3---3:4:5)
    
    # Let's take a look at it
    plot(g1)
    

    # Say we are interested in the subgraph consisting of vertex 1 and all
    # other vertices it is connected to
    
    g2 <- induced_subgraph(g1, c(1, neighbors(g1,1)))
    plot(g2)
    

    【讨论】:

    • 谢谢。这种方法,(以及thelatemail 制作下面的自我图的方法)子集到邻居节点。尽管 make_ego_graph 方法具有更大的灵活性,但我发现邻居方法更容易理解。我还想摆脱邻居之间的边缘(例如在 3-4 和 3-5 之间)。为此,我最终使用了上面的邻居方法,然后使用了 delete_edges 方法。首先找到感兴趣的节点名称然后... not_node_indices
    【解决方案2】:

    ?make_ego_graph 应该这样做,如果order=1

    g <- make_graph(c(1, 2, 2, 3, 3, 4, 5, 6), directed = FALSE)
    V(g)$name <- letters[1:6]
    g
    #IGRAPH  UN-- 6 4 -- 
    #+ attr: name (v/c)
    #+ edges from 657f0a0 (vertex names):
    #[1] a--b b--c c--d e--f
    
    make_ego_graph(g, order=1, nodes=2)
    #[[1]]
    #IGRAPH UN-- 3 2 -- 
    #+ attr: name (v/c)
    #+ edges from 69681da (vertex names):
    #[1] a--b b--c
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多