Converting between graph classes
Source:vignettes/Converting-between-graph-classes.Rmd
Converting-between-graph-classes.Rmd
Converting between graph classes
As mentioned above, a common network
analysis workflow includes the conversion of graph objects between
various formats. The igraph
and statnet
packages provide some very basic functions for this, that are specific
to the types of objects that are used in these packages themselves:
Graph object conversion | |
Convert to an adjacency matrix | |
---|---|
igraph |
|
network |
|
Convert to an adjacency list | |
igraph |
|
network | — |
Convert to an edge list | |
igraph |
|
network |
|
Make the network directed | |
snafun | — |
igraph |
|
network | — |
Make the network undirected | |
snafun |
|
igraph |
|
network |
|
Project a bipartite graph | |
snafun | — |
igraph |
|
network | — |
Convert to a line graph | |
snafun | — |
igraph |
|
network | — |
Conversion between various formats is a lot easier with the help of
the snafun
package. You only need to know some very easy
function names to convert between the common graph classes. Here is an
overview of which function to use for which conversion:
Convert between various formats | ||||
Using the consistent functions of snafun | ||||
INPUT | OUTPUT | |||
---|---|---|---|---|
edgelist | matrix | igraph | network | |
edgelist | to_edgelist() |
to_matrix() |
to_igraph() |
to_network() |
matrix | to_edgelist() |
to_matrix() |
to_igraph() |
to_network() |
igraph | to_edgelist() |
to_matrix() |
to_igraph() |
to_network() |
network | to_edgelist() |
to_matrix() |
to_igraph() |
to_network() |
Conversion includes bipartite graphs.
Check the arguments for the various options. |