问题描述
我想构造一个有向网络图的子图,其中所有顶点共享某个顶点属性(例如,V(Grph)$ year =="1952")及其一阶(立即数)邻居,仅基于出学位.
I'd like to construct a subgraph of a graph of a directed network with all the vertices sharing a certain vertex attribute (say, V(Grph)$year == "1952") and their first-order (immediate) neighbors, based only on the out-degree.
我尝试了ego()
,make_ego_graph()
,neighbors()
和adjacent_vertices()
.
例如,CitGraph <- make_ego_graph(Grph, 1, nodes = which(V(Grph)$year=="1952"), mode = "out")
产生一张图表列表(而不是一张完整的图表),令人惊讶的是,今年要绘制5万个顶点需要花费两个小时,而要指出的是15万个邻居.
For instance,CitGraph <- make_ego_graph(Grph, 1, nodes = which(V(Grph)$year=="1952"), mode = "out")
yields a list of graphs (and not a single comprehensive one) and surprisingly takes two hours for 50k vertices in this year and 150k neighbors being pointed to.
我想到的一种方法是将列表中的所有这些图进行汇总,但不知道如何进行.另外,我想保留顶点属性,因为我的最终目标是根据另一个顶点属性(在这种情况下为地理位置)来计算assortativity_nominal()
.
One approach I could think of would be to aggregate all these graphs in the list but don't know how. Also, I'd like to preserve the vertex attributes as my ultimate goal is to calculate assortativity_nominal()
, based on another vertex attribute (geographical location in this case).
提前感谢您的任何建议!
Thanks in advance for any suggestion you may have!
推荐答案
实际上,make_ego_graph
返回列表nodes
中每个顶点的邻域图.
Indeed make_ego_graph
returns a graph for the neighbourhood for each of the vertices in the list nodes
.
我建议您使用需要包含在子图中的边列表而不是顶点列表来解决该问题.假设像list_of_vertices <- V(Grph)$year == "1952"
那样解决了您的顶点列表,或者无论您的条件如何,您都将执行类似的操作
I suggest you to solve it using the list of edges you need to include in your subgraph, instead of the list of vertices. Assuming your list of vertices is resolved like list_of_vertices <- V(Grph)$year == "1952"
or whatever it is your condition, you would do something like,
list_of_edges <- E(your_graph)[from(list_of_vertices) | to(list_of_vertices)]
your_subgraph <- subgraph.edges(your_graph, list_of_edges)
(我正在使用有向图.)
(I'm using a directed graph.)
希望有帮助.
这篇关于igraph-邻居作为子图-make_ego_graph()作为单个图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!