| Title: | Organize, Handle, and Explore Ecological Multilayer Networks |
|---|---|
| Description: | Data and analysis of ecological multilayer networks, including standardization of data structures and functions to convert between them. Includes an interactive multilayer network visualizer (beta, paper forthcoming), and a collection of 78 empirical ecological multilayer network datasets. This work was supported by research grant ISF (Israel Science Foundation) 1281/20 to Shai Pilosof. Noa Frydman (2023) <doi:10.1111/2041-210X.14225>. |
| Authors: | Noa Frydman [aut], Shai Pilosof [aut, fnd], Shirly Freilikhman [aut], Geut Galai [cre] |
| Maintainer: | Geut Galai <[email protected]> |
| License: | CC BY 4.0 |
| Version: | 1.2.0 |
| Built: | 2026-05-13 14:50:23 UTC |
| Source: | https://github.com/ecological-complexity-lab/emln |
Automatically identifies if the input is a matrix or an edge list and creates
a monolayer object.
create_monolayer_network( x, directed = NULL, bipartite = NULL, group_names = c("set_cols", "set_rows"), node_metadata = NULL )create_monolayer_network( x, directed = NULL, bipartite = NULL, group_names = c("set_cols", "set_rows"), node_metadata = NULL )
x |
input data in the format of a matrix, edge list or an igraph object. |
directed |
Is the network directed? |
bipartite |
Is the network bipartite? Ignored when the input is an igraph object. |
group_names |
For bipartite networks: name of the groups in the columns and rows, respectively (e.g., parasites and hosts). |
node_metadata |
Following the igraph method of |
Converts between edge list and matrix formats and creates a
monolayer object. It a wrapper function for
list_to_matrix, matrix_to_list_unipartite, matrix_to_list_bipartite. Node metadata can only be included with an edge list input.
A monolayer object.
list_to_matrix, matrix_to_list_unipartite, monolayer.
library(igraph) # A bipartite network from package bipartte x <- create_monolayer_network(bipartite::memmott1999, bipartite = TRUE, directed = FALSE, group_names = c('Animals','Plants')) # A bipartite network as an igraph object # Generate a random bipartite network in igraph g <- igraph::sample_bipartite(10,16,p=0.3, type = 'gnp', directed = TRUE, mode = 'in') V(g)$name <- letters # name the nodes V(g)$gender <- sample(c('F','M'), size = 26, replace = TRUE) # Add a node attribute E(g)$weight=runif(ecount(g)) # Add edge weights plot(g, layout=layout.bipartite) create_monolayer_network(g, group_names = c('Parasites','Hosts'))library(igraph) # A bipartite network from package bipartte x <- create_monolayer_network(bipartite::memmott1999, bipartite = TRUE, directed = FALSE, group_names = c('Animals','Plants')) # A bipartite network as an igraph object # Generate a random bipartite network in igraph g <- igraph::sample_bipartite(10,16,p=0.3, type = 'gnp', directed = TRUE, mode = 'in') V(g)$name <- letters # name the nodes V(g)$gender <- sample(c('F','M'), size = 26, replace = TRUE) # Add a node attribute E(g)$weight=runif(ecount(g)) # Add edge weights plot(g, layout=layout.bipartite) create_monolayer_network(g, group_names = c('Parasites','Hosts'))
This function creates a multilayer network from multiple matrices / link lists.
create_multilayer_network( list_of_layers, bipartite, directed, interlayer_links = NULL, layer_attributes = NULL, state_node_attributes = NULL, physical_node_attributes = NULL )create_multilayer_network( list_of_layers, bipartite, directed, interlayer_links = NULL, layer_attributes = NULL, state_node_attributes = NULL, physical_node_attributes = NULL )
list_of_layers |
List of matrices or list of link lists (format
|
bipartite |
Is the network bipartite? Must be provided (no default value). |
directed |
Is the network directed? Must be provided (no default value). |
interlayer_links |
Interlayer extended edge list of the format
|
layer_attributes |
Optional. A data frame with layer attributes. The
first column must be called |
state_node_attributes |
Optional. Additional information on physical nodes in
layers. Must contain columns |
physical_node_attributes |
Optional. Additional information on physical nodes. Must contain column |
Input of list_of_layers is handled by the function
create_monolayer_network; see it's description for details on input.
If using matrices as input, they should contain row and column names. If link lists are provided as input column names should be
from to weight.
When using link lists, it is possible to include link
attributes. In that case the headers of all the link lists and, if
included, the interlayer links, must be the same (after the weight), even if some attributes
are included in only some layers (see detailed example in the code accompanying the package). Missing link attributes can be set to NA.
If interlayer links are provided, then layer_attributes must also be provided. Specify layer and nodes by UNIQUE names (not IDs). Layer names should correspond to those provided in layer_attributes.
Attributes of state nodes can be provided with state_node_attributes. If
provided, then columns layer_name and node_name must be
included.
For compatibility with function load_emln the output contains
description and references. The value of any missing data
frames in the multilayer object will be set to NULL.
See multiple example in the code accompanying the package
A multilayer object (see ?multilayer).
multilayer, create_monolayer_network
library(tibble) pond_1 <- matrix(c(0,1,1,0,0,1,0,0,0), byrow = TRUE, nrow = 3, ncol = 3, dimnames = list(c('pelican','fish','crab'), c('pelican','fish','crab'))) pond_2 <- matrix(c(0,1,0,0,0,1,0,0,0), byrow = TRUE, nrow = 3, ncol = 3, dimnames = list(c('pelican','fish','crab'), c('pelican','fish','crab'))) pond_3 <- matrix(c(0,1,1,0,0,1,0,0,0), byrow = TRUE, nrow = 3, ncol = 3, dimnames = list(c('pelican','fish','tadpole'), c('pelican','fish','tadpole'))) layer_attrib <- tibble(layer_id=1:3, layer_name=c('pond_1','pond_2','pond_3'), location=c('valley','mid-elevation','uphill')) # Create the ELL tibble with interlayer links. interlayer <- tibble(layer_from=c('pond_1','pond_1','pond_1'), node_from=c('pelican','crab','pelican'), layer_to=c('pond_2','pond_2','pond_3'), node_to=c('pelican','crab','pelican'), weight=1) # This is a directed network so the links should go both ways, # even though they are symmetric. interlayer_2 <- interlayer[,c(3,4,1,2,5)] names(interlayer_2) <- names(interlayer) interlayer <- rbind(interlayer, interlayer_2) multilayer <- create_multilayer_network(list_of_layers = list(pond_1, pond_2, pond_3), layer_attributes = layer_attrib, interlayer_links = interlayer, bipartite = FALSE, directed = TRUE)library(tibble) pond_1 <- matrix(c(0,1,1,0,0,1,0,0,0), byrow = TRUE, nrow = 3, ncol = 3, dimnames = list(c('pelican','fish','crab'), c('pelican','fish','crab'))) pond_2 <- matrix(c(0,1,0,0,0,1,0,0,0), byrow = TRUE, nrow = 3, ncol = 3, dimnames = list(c('pelican','fish','crab'), c('pelican','fish','crab'))) pond_3 <- matrix(c(0,1,1,0,0,1,0,0,0), byrow = TRUE, nrow = 3, ncol = 3, dimnames = list(c('pelican','fish','tadpole'), c('pelican','fish','tadpole'))) layer_attrib <- tibble(layer_id=1:3, layer_name=c('pond_1','pond_2','pond_3'), location=c('valley','mid-elevation','uphill')) # Create the ELL tibble with interlayer links. interlayer <- tibble(layer_from=c('pond_1','pond_1','pond_1'), node_from=c('pelican','crab','pelican'), layer_to=c('pond_2','pond_2','pond_3'), node_to=c('pelican','crab','pelican'), weight=1) # This is a directed network so the links should go both ways, # even though they are symmetric. interlayer_2 <- interlayer[,c(3,4,1,2,5)] names(interlayer_2) <- names(interlayer) interlayer <- rbind(interlayer, interlayer_2) multilayer <- create_multilayer_network(list_of_layers = list(pond_1, pond_2, pond_3), layer_attributes = layer_attrib, interlayer_links = interlayer, bipartite = FALSE, directed = TRUE)
@format Data set of multilayer networks
descriptionsdescriptions
An object of class tbl_df (inherits from tbl, data.frame) with 89 rows and 10 columns.
@source create
@examples data(descriptions)
This function creates a list of igraph objects from the network layers. Interlayer links are not included.
get_igraph(multilayer, bipartite, directed)get_igraph(multilayer, bipartite, directed)
multilayer |
The multilayer object. |
bipartite |
Is the network bipartite? Must be provided (no default value). |
directed |
Is the network directed? Must be provided (no default value). |
If link, physical node or state node attributes are included in the multilayer network they are passed to the igraph objects.
A list:
layers_igraph A list of igraph objects, one per layer
nodes A table of physical nodes, as in the multlayer object.
state_nodes_map A table with state nodes to map the nodes to the row and columns of a SAM.
# See examples in: # https://emln.ecomplab.com/multilayer.html#To_igraph_objects# See examples in: # https://emln.ecomplab.com/multilayer.html#To_igraph_objects
This function creates a supra-adjacency matrix from a multilayer object.
get_sam( multilayer, bipartite, directed, sparse = FALSE, remove_zero_rows_cols = FALSE )get_sam( multilayer, bipartite, directed, sparse = FALSE, remove_zero_rows_cols = FALSE )
multilayer |
The multilayer object. |
bipartite |
Is the network bipartite? Must be provided (no default value). |
directed |
Is the network directed? Must be provided (no default value). |
sparse |
Should the returned matrix be a sparse matrix (class Matrix)? Defaults to false. |
remove_zero_rows_cols |
Should rows and columns that sum to 0 be removed? Defaults to false. |
By default, a SAM contains all the nodes in all the layers. However,
not all nodes always occur in all layers. This will be reflected in the
state_nodes_map: When layer and node ids are NA that means that the
node did not occur in the layer.
A node may not have links across all
the layers. In that case, its row or column sum will be zero. This can happen in a
directed matrix (see toy example for unipartite network), or in
diagonally-coupled networks (see toy bipartite example). The user can choose to remove rows and columns that sum to zero by setting remove_zero_rows_cols to TRUE.
A list:
M The SAM. Can also be sparse.
nodes A table of physical nodes, as in the multlayer object.
state_nodes_map A table with state nodes to map the nodes to the row and columns of the SAM.
# See examples in: # https://emln.ecomplab.com/multilayer.html#To_supra-adjacency_matrices# See examples in: # https://emln.ecomplab.com/multilayer.html#To_supra-adjacency_matrices
Convert an edge list to a matrix. Can handle unipartite and bipartite networks.
list_to_matrix( x, directed = FALSE, bipartite = TRUE, group_names = c("set_cols", "set_rows"), node_metadata = NULL )list_to_matrix( x, directed = FALSE, bipartite = TRUE, group_names = c("set_cols", "set_rows"), node_metadata = NULL )
x |
An edge list of the format |
directed |
Is the network directed? |
bipartite |
Is network bipartite? |
group_names |
For bipartite networks: name of the groups in the columns and rows, respectively (e.g., parasites and hosts). |
node_metadata |
Following the igraph method of |
It is also possible to add node attributes. For this, it uses
igraph. The first column in the node_metadata data frame should have
the names of the nodes in the edge list.
A monolayer object.
Functions create_monolayer_network, monolayer and graph_from_data_frame from igraph.
library(dplyr) network <- load_emln(17) nodes <- network$nodes links<-subset(network$extended_ids %>% filter(layer_from==1), select=c(node_from, node_to, weight)) list_to_matrix(links, directed = TRUE, bipartite = FALSE, node_metadata = nodes) # See examples in: # https://emln.ecomplab.com/monolayer.html#Unipartitelibrary(dplyr) network <- load_emln(17) nodes <- network$nodes links<-subset(network$extended_ids %>% filter(layer_from==1), select=c(node_from, node_to, weight)) list_to_matrix(links, directed = TRUE, bipartite = FALSE, node_metadata = nodes) # See examples in: # https://emln.ecomplab.com/monolayer.html#Unipartite
Load a specific network by specifying its ID.
load_emln(network_id)load_emln(network_id)
network_id |
The network ID. |
Use the search_emln and view_emln functions to obtain network IDs.
A multilayer object (see ?multilayer).
multilayer
load_emln(network_id = 38)load_emln(network_id = 38)
Convert an incidence matrix to an edge list.
matrix_to_list_bipartite(x, group_names = c("set_cols", "set_rows"))matrix_to_list_bipartite(x, group_names = c("set_cols", "set_rows"))
x |
An incidence matrix. |
group_names |
Name of the groups in the columns and rows, respectively (e.g., parasites and hosts). |
Assigns column and row names if those do not exist. Cannot handle node attributes/metadata. Always assumes an undirected network.
A monolayer object.
create_monolayer_network, monolayer
# See examples in: https://emln.ecomplab.com/monolayer.html#Bipartite matrix_to_list_bipartite(bipartite::memmott1999, group_names = c('Animals', 'Plants'))# See examples in: https://emln.ecomplab.com/monolayer.html#Bipartite matrix_to_list_bipartite(bipartite::memmott1999, group_names = c('Animals', 'Plants'))
Convert an adjacency matrix to an edge list.
matrix_to_list_unipartite(x, directed)matrix_to_list_unipartite(x, directed)
x |
An adjacency or incidence matrix. |
directed |
Is the network directed? TRUE/FALSE |
Assigns column and row names if those do not exist. Cannot handle node attributes/metadata.
A monolayer object
create_monolayer_network, monolayer
# See examples in: # https://emln.ecomplab.com/monolayer.html#Unipartite # Generate a matrix with random weighted interactions x <- matrix(rbinom(100,1,0.6),10,10) x <- x*round(runif(100,1,5),0) # run matrix_to_list_unipartite(x, directed = TRUE)# See examples in: # https://emln.ecomplab.com/monolayer.html#Unipartite # Generate a matrix with random weighted interactions x <- matrix(rbinom(100,1,0.6),10,10) x <- x*round(runif(100,1,5),0) # run matrix_to_list_unipartite(x, directed = TRUE)
A network object of class monolayer contains all the necessary information and R objects to perform future analyses on a monolayer network, and in particular analyses using Infomap.
A list with:
mode: bipartite (B) or unipartite (U)
directed: TRUE/FALSE
nodes: a tibble with information on the nodes (name, id, type, other attributes)
mat: the network in a matrix format
edge_list: the network in an edge list format
igraph_object: the igraph object of the network
list_to_matrix, matrix_to_list_unipartite, matrix_to_list_bipartite, create_network_object
A network object of class multilayer contains all the necessary information and R objects that define a multilayer network.
A list with:
nodes Physical nodes. First column is a unique node id. Node attributes are included if provided as input.
layers Information on layers.
extended An extended link list of the format layer_from node_from layer_to node_to weight. All nodes and layers are identified by names.
extended_ids An extended link list of the format layer_from node_from layer_to node_to weight. All nodes and layers are identified by unique IDs automoatically generated.
state_nodes List of state nodes of the format layer_id node_id layer_name node_name. Also includes state node attributes if provided as input.
description For compatibility with load_emln.
references For compatibility with load_emln.
create_multilayer_network
Writes an EMLN multilayer object as a set of CSV files consumed
by MiRA's CSV importer. Three files are always written; a fourth
(<prefix>_state_nodes.csv) is added when per-(layer, node)
attributes are present.
multilayer_to_csv( multilayer, dir, prefix = "network", bipartite = FALSE, setA_type = NULL, directed = NULL )multilayer_to_csv( multilayer, dir, prefix = "network", bipartite = FALSE, setA_type = NULL, directed = NULL )
multilayer |
A multilayer object (created by
|
dir |
Directory to write the CSV files to. Created if it does not already exist. |
prefix |
Character. File name prefix. Defaults to |
bipartite |
Logical. Whether the network is bipartite. Defaults to
|
setA_type |
Optional character. The |
directed |
Logical or NULL. Whether the network is directed. If NULL (default), auto-detected by checking intralayer edge symmetry. |
The CSV files follow the schema accepted by MiRA's CSV importer:
edges: layer_from, node_from, layer_to, node_to,
weight (+ any extra link attributes).
layers: layer_id, layer_name (+ latitude,
longitude, bipartite and any extra layer attributes).
nodes: node_name (+ node_type and any extra
physical node attributes, same across all layers).
node_group is renamed to node_type.
state_nodes (written only when extra per-(layer, node)
attributes exist): layer_name, node_name + extra columns.
Use this when the same node has different attribute values in
different layers (e.g. abundance, module membership).
The directed flag is not written to the CSV files; it is a property
you specify in MiRA's CSV import dialog at load time.
Invisibly returns a named character vector of file paths written
(edges, layers, nodes, and optionally
state_nodes).
MiRA (Multilayer Interactive Rendering Application) is a browser-based interactive visualization tool for multilayer networks, available at https://mira.ecomplab.com/.
If you use MiRA in published research, please cite:
Nehoray SM, Bloch Y, Pilosof S (2026). Interactively visualizing biological multilayer networks using MiRA. arXiv:2605.09597 [cs.SI]. doi:10.48550/arXiv.2605.09597
Feedback and bug reports: https://github.com/Ecological-Complexity-Lab/MiRA/issues.
multilayer_to_json, plot_multilayer
net <- load_emln(14) multilayer_to_csv(net, dir = "tests/out/", prefix = "kefi", bipartite = TRUE)net <- load_emln(14) multilayer_to_csv(net, dir = "tests/out/", prefix = "kefi", bipartite = TRUE)
Converts an EMLN multilayer object to JSON format compatible with
MiRA, the multilayer interactive R-network app.
multilayer_to_json( multilayer, file = NULL, bipartite = FALSE, setA_type = NULL, directed = NULL, directed_interlayer = NULL )multilayer_to_json( multilayer, file = NULL, bipartite = FALSE, setA_type = NULL, directed = NULL, directed_interlayer = NULL )
multilayer |
A multilayer object (created by |
file |
Optional file path to write the JSON to. If NULL, returns the JSON string. |
bipartite |
Logical. Whether the network is bipartite. Defaults to
|
setA_type |
Optional character. The |
directed |
Logical or NULL. Whether intralayer links are directed. If NULL (default), auto-detected by checking intralayer edge symmetry. |
directed_interlayer |
Logical or NULL. Whether interlayer links are
directed. If NULL (default), inherits from |
The JSON output contains four arrays matching MiRA's expected format:
nodes: Physical nodes with node_id, node_name, and
any extra attributes. For bipartite networks, node_group is mapped to
node_type.
layers: Layer metadata with layer_id, layer_name,
and extra attributes. For bipartite networks, a bipartite: true flag
is added; if setA_type is given it is also written per layer.
extended: The extended edge list with layer_from,
node_from, layer_to, node_to, weight, and any
link attributes.
state_nodes: State node map with layer_id, node_id,
layer_name, node_name, plus any extra per-(layer, node)
attributes (e.g. abundance, module).
Top-level flags directed and (when set) directed_interlayer
indicate edge directionality globally; they are not repeated per link.
If file is NULL, returns the JSON string invisibly.
If file is specified, writes JSON to disk and returns the file path
invisibly.
MiRA (Multilayer Interactive Rendering Application) is a browser-based interactive visualization tool for multilayer networks, available at https://mira.ecomplab.com/.
If you use MiRA in published research, please cite:
Nehoray SM, Bloch Y, Pilosof S (2026). Interactively visualizing biological multilayer networks using MiRA. arXiv:2605.09597 [cs.SI]. doi:10.48550/arXiv.2605.09597
Feedback and bug reports: https://github.com/Ecological-Complexity-Lab/MiRA/issues.
plot_multilayer, create_multilayer_network, load_emln
# Export to file net <- load_emln(14) multilayer_to_json(net, file = "tests/my_network.json", bipartite = TRUE) # Bipartite with explicit Set A ordering multilayer_to_json(net, bipartite = TRUE, setA_type = "pollinator") # Get JSON string json_str <- multilayer_to_json(net)# Export to file net <- load_emln(14) multilayer_to_json(net, file = "tests/my_network.json", bipartite = TRUE) # Bipartite with explicit Set A ordering multilayer_to_json(net, bipartite = TRUE, setA_type = "pollinator") # Get JSON string json_str <- multilayer_to_json(net)
Converts an EMLN multilayer object to JSON and opens MiRA, the
multilayer interactive R-network app, in the default web browser.
plot_multilayer( multilayer, bipartite = FALSE, setA_type = NULL, directed = NULL, directed_interlayer = NULL, port = 8080, mira_path = NULL, browser = getOption("browser") )plot_multilayer( multilayer, bipartite = FALSE, setA_type = NULL, directed = NULL, directed_interlayer = NULL, port = 8080, mira_path = NULL, browser = getOption("browser") )
multilayer |
A multilayer object (created by |
bipartite |
Logical. Whether the network is bipartite. Defaults to
|
setA_type |
Optional character. The |
directed |
Logical or NULL. Whether intralayer links are directed. If NULL (default), auto-detected by checking intralayer edge symmetry. |
directed_interlayer |
Logical or NULL. Whether interlayer links are
directed. If NULL (default), inherits from |
port |
Integer. Port for the local HTTP server. Default is 8080. |
mira_path |
Character. Path to the MiRA web-app directory. If NULL
(default), uses the copy bundled with the package
( |
browser |
Choose the specific browser to open MiRA in. Defaults to
the system default via |
The function:
Converts the multilayer object to JSON via multilayer_to_json
Starts a local HTTP server (using httpuv) that serves the
MiRA app and the network JSON
Opens the browser with auto-load enabled
The server runs in the background. Call httpuv::stopServer(handle) or
close R to stop it. The JSON data is kept in memory and never written to disk.
Invisibly returns the server handle. Use
httpuv::stopServer(handle) to stop the server when done.
MiRA (Multilayer Interactive Rendering Application) is a browser-based interactive visualization tool for multilayer networks, available at https://mira.ecomplab.com/.
If you use MiRA in published research, please cite:
Nehoray SM, Bloch Y, Pilosof S (2026). Interactively visualizing biological multilayer networks using MiRA. arXiv:2605.09597 [cs.SI]. doi:10.48550/arXiv.2605.09597
Feedback and bug reports: https://github.com/Ecological-Complexity-Lab/MiRA/issues.
multilayer_to_json, create_multilayer_network, load_emln
if (interactive()){ net <- load_emln(60) srv <- plot_multilayer(net, bipartite = TRUE, setA_type = "pollinator") # When done: httpuv::stopServer(srv) }if (interactive()){ net <- load_emln(60) srv <- plot_multilayer(net, bipartite = TRUE, setA_type = "pollinator") # When done: httpuv::stopServer(srv) }
Search the database for networks depending on search parameters specified below.
search_emln( ecological_network_type = NULL, multilayer_network_type = NULL, state_nodes = NULL, node_number_minimum = NULL, layer_number_minimum = NULL, weighted = NULL, interlayer = NULL, directed = NULL )search_emln( ecological_network_type = NULL, multilayer_network_type = NULL, state_nodes = NULL, node_number_minimum = NULL, layer_number_minimum = NULL, weighted = NULL, interlayer = NULL, directed = NULL )
ecological_network_type |
One of: Seed-Dispersal, Pollination, Food-Web, Host-Parasite, Multiple, Plant-Herbivore, Anemone-Fish, Plant-Ant |
multilayer_network_type |
Environment, Temporal, Multiplex, Perturbation, Spatial |
state_nodes |
TRUE/FALSE |
node_number_minimum |
The minimum number of layers wanted in the network |
layer_number_minimum |
The minimum number of layers wanted in the network |
weighted |
TRUE/FALSE |
interlayer |
TRUE/FALSE |
directed |
TRUE/FALSE |
A tibble containing the network id, and all the search arguments for each of the networks that are compatible with the search.
# See examples in: # https://emln.ecomplab.com/data.html#Browsing_the_data # Generates a tibble of all the networks in the package that are pollination networks search_emln(ecological_network_type = 'Plant-Ant') # Generates a tibble of all the networks in the package that have state nodes and are temporal search_emln(multilayer_network_type = 'Temporal', state_node = TRUE)# See examples in: # https://emln.ecomplab.com/data.html#Browsing_the_data # Generates a tibble of all the networks in the package that are pollination networks search_emln(ecological_network_type = 'Plant-Ant') # Generates a tibble of all the networks in the package that have state nodes and are temporal search_emln(multilayer_network_type = 'Temporal', state_node = TRUE)
View the database interactively.
view_emln()view_emln()
An interactive GUI for browinsg through networks.