Where are the vertex names in an iGraph graph

Henning Piezunka picture Henning Piezunka · Jun 8, 2012 · Viewed 20.9k times · Source

My general problem is that I loose the vertex names / labels (not sure about the right word here) when generating a graph using iGraph.

I have an edge list IC_edge_sub of a bipartite network, that looks like the following:

  new_individualID new_companyID
1             <NA>     10024354c
3        10069415i      2020225c
4        10069415i     16020347c
5        10069272i      2020225c
6        10069272i     16020347c
7        10069274i      2020225c

I then create a graph element:

IC_projected_graphs <- bipartite.projection(IC_twomode, types = 
                         is.bipartite(IC_twomode)$type)

Then collapse it to identify only connections between companyIDs

IC_projected_graphs <- bipartite.projection(IC_twomode, types =   
                         is.bipartite(IC_twomode)$type)

And then get the adjacency matrix:

CC_matrix_IC_based <- get.adjacency(CC_graph_IC_based); CC_matrix_IC_based

In iGraph node numbering starts at zero and thus also the matrix naming starts at zero. However, I would instead now need the "new_companyID" as specified in the 2nd column of the edgelist in the eventual CC_matrix_IC_based matrix.

Can you help me how to use the information form the original edgelist to put in rownames and colnames in the eventual adjacency matrix?

I googled it and searched stack flow, but could not really find a working answer. Thanks a lot for your help

Answer

Tam&#225;s picture Tamás · Jun 8, 2012

Vertex names are usually stored in a vertex attribute named name in igraph. So, if your graph is stored in the variable g, then you can use V(g)$name to retrieve the names of all the vertices.