View source: R/multilayer_to_json.R
| multilayer_to_json | R Documentation |
Converts an EMLN multilayer object to JSON format compatible with the
Multilayer Network Visualizer web app.
multilayer_to_json(multilayer, file = NULL, bipartite = FALSE, directed = 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
|
directed |
Logical or NULL. Whether the network is directed. If NULL (default), auto-detected by checking edge list symmetry. |
The JSON output contains four arrays matching the visualizer'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.
extended: The extended edge list with layer_from,
node_from, layer_to, node_to, weight, and any
link attributes. For directed networks, a directed: true flag is
added to each link.
state_nodes: State node map with layer_id, node_id,
layer_name, node_name.
If file is NULL, returns the JSON string invisibly.
If file is specified, writes JSON to disk and returns the file path
invisibly.
The Multilayer Network Visualizer that this function targets is currently in beta. Feedback and bug reports are welcome at https://github.com/Ecological-Complexity-Lab/emln/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)
# Get JSON string
json_str <- multilayer_to_json(net)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.