View source: R/create_multilayer_network.R
| create_multilayer_network | R Documentation |
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
)
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.