Igraph - Neighbors as a subgraph - make_ego_graph () as a single graph

I would like to build a subgraph of a directed network graph with all the vertices sharing a certain vertex attribute (for example, V (Grph) $ year == "1952") and their first order (immediate) neighbors based only on the external level.

I tried ego() , make_ego_graph() , neighbors() and adjacent_vertices() .

For example, CitGraph <- make_ego_graph(Grph, 1, nodes = which(V(Grph)$year=="1952"), mode = "out") gives a list of graphs (and is not one comprehensive) and surprisingly takes two hours for the peaks of 50k this year and points to 150 thousand neighbors.

One approach that I could think of would be to combine all these graphs in a list, but I don't know how to do this. In addition, I would like to preserve the vertex attributes, since my ultimate goal is to calculate assortativity_nominal() based on another vertex attribute (in this case, geographic location).

Thanks in advance for any suggestion you may have!

+8
r igraph network-analysis
source share
1 answer

Indeed, make_ego_graph returns a graph for the neighborhood for each of the vertices in the nodes list.

I suggest you solve it using a list of edges that you want to include in your subgraph, rather than a list of vertices. Assuming your list of vertices is allowed as list_of_vertices <- V(Grph)$year == "1952" or whatever its state, 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 use a directed graph.)

Hope this helps.

+5
source share

All Articles