Create a subgraph from the neighborhood of specific vertices in igraph

André Ourednik, Friday, September 21, 2018

Many user of igraph for R expect the functions ego() and make_ego_graph() , that take a list of vertices as input, to generate a new graph composed of the neighbors of these vertices. Unfortunately, these functions do no such thing. They generate a list of igraph.vs objects, which cannot be further treated as an igraph object. This must have some historic reason but is currently unpractical, considering that neigborhood-based subgraph genaration is a feature so common that a software like Cytoscape even dedicates one of the few buttons of its GUI to its use.

There is a workaround, though. It lies in the combination of  unlist()  and the function induced_subgraph() , also part of the igraph package for R. Here is a short example of use:

 

 

 

  •  
  •  
  •  
  •  
  •  
  •  
Cite as: André Ourednik (2018) « Create a subgraph from the neighborhood of specific vertices in igraph » in Maps and Spaces from https://ourednik.info/maps/2018/09/21/create-a-subgraph-from-the-neighborhood-of-specific-vertices-in-igraph/ [Last-seen October 24th 2018].
Category: Tools