【问题标题】:How to plot a subset of all the vertices of a graph that are linked to same vertex using igraph in R?如何使用 R 中的 igraph 绘制连接到同一顶点的图的所有顶点的子集?
【发布时间】:2016-04-14 17:21:33
【问题描述】:

我想查找并绘制连接到网络“g”中顶点 #18 的所有顶点的子集,不仅包括相邻节点(邻居),还包括那些有任何可能路径的节点

g <- (make_full_graph(10) + make_full_graph(10))
plot(g) #plots 2 separate networks:

找到所有具有到顶点 #18 的路径的顶点后,生成的子图应如下所示:

有什么想法吗?谢谢!

【问题讨论】:

    标签: r plot subset igraph


    【解决方案1】:

    不要让这个问题悬而未决......

    您想要由包含节点 18 的连接组件组成的子图。唯一有点棘手的是 induced_subgraph 重新编号节点,因此如果要保留原始编号,则需要显式设置标签在子图上。

    ## Your sample graph
    g <- (make_full_graph(10) + make_full_graph(10))
    plot(g)
    
    ## Get Connected component for node 18
    Comp = components(g)
    Comp18 = which(Comp$membership == Comp$membership[18])
    
    ## Extract subgraph and name nodes based on old numbering
    g2 = induced_subgraph(g, Comp18)
    g2 = set_vertex_attr(g2, "label", value = Comp18 )
    plot(g2)
    

    【讨论】:

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