library(emln)
The emln package ships with MiRA, an interactive
Multilayer Network Visualizer — a browser-based web app
for exploring multilayer networks in multiple views. You can launch it
directly from R with plot_multilayer(), which starts a
local server and opens the app in your browser. Alternatively, export
your network to JSON or CSV and upload it to the standalone version of the app.
Note: Feedback and bug reports for MiRA are welcome at the MiRA GitHub issues page.
If you use MiRA in published research, please cite: Nehorai S, Bloch Y and Pilosof S. Interactively visualizing biological multilayer networks using MiRA. (forthcoming)
plot_multilayer() converts the multilayer object to
JSON, starts a local HTTP server using httpuv, and opens
MiRA in your browser. The network data is held in memory — nothing is
written to disk. The function returns the server handle, which you use
to stop the server when you are done.
Important: bipartite is not
auto-detected; you must set it explicitly. The directed
argument defaults to NULL and is auto-detected from edge
symmetry.
Two additional optional arguments are worth knowing:
setA_type — for bipartite networks, specifies which
node_type value is displayed as Set A (the top row). By
ecological convention this is the higher trophic level
(e.g. "pollinator", "parasite"). If omitted,
MiRA falls back to alphabetical ordering.directed_interlayer — controls whether interlayer links
are directed independently from intralayer links. Useful for temporal
multilayer networks where interlayer links represent time progression.
If NULL (default), it inherits the value of
directed.# Load data
net <- load_emln(65)
# Open MiRA in the browser
srv <- plot_multilayer(net, bipartite = TRUE, setA_type = "pollinator", browser = 'Chrome')
# When done, stop the local server
httpuv::stopServer(srv)
The app opens at http://localhost:8080?autoload=true
(the port increments automatically if 8080 is busy). MiRA provides seven
visualization modes:
Use multilayer_to_json() to save your network as a JSON
file compatible with the visualizer’s Import button.
This is useful when you want to share the network, reload it later
without re-running R, or upload it to the standalone app.
multilayer_to_json(net, file = "net60.json", bipartite = TRUE)
If you omit file, the function returns the JSON string —
useful for passing it to another function or inspecting the output
programmatically.
json_str <- multilayer_to_json(net, bipartite = TRUE)
cat(substr(json_str, 1, 500)) # preview the first 500 characters
The JSON object contains four arrays that the visualizer expects:
| Array | Contents |
|---|---|
nodes |
Physical nodes: node_id, node_name, and
any extra node attributes |
layers |
Layer metadata: layer_id, layer_name, and
any extra layer attributes. For bipartite networks a
bipartite: true flag is added; if setA_type is
provided it is also written per layer. |
extended |
Extended edge list: layer_from, node_from,
layer_to, node_to, weight, and
any extra link attributes |
state_nodes |
State node map: layer_id, node_id,
layer_name, node_name, plus any extra
per-(layer, node) attributes (e.g. abundance, module membership) |
Two top-level flags control edge directionality:
directed (intralayer) is set automatically from edge
symmetry unless overridden; directed_interlayer is written
only when set explicitly, and defaults to inheriting from
directed.
If you prefer a tabular format, multilayer_to_csv()
writes three or four CSV files to a directory of your choice, following
the schema accepted by the visualizer’s CSV importer.
multilayer_to_csv(net, dir = "out/", prefix = "net60", bipartite = TRUE)
The files written are:
| File | Contents |
|---|---|
net60_edges.csv |
Extended edge list: layer_from, node_from,
layer_to, node_to, weight, plus
any extra link attributes |
net60_layers.csv |
Layer metadata: layer_id, layer_name, plus
any extra layer attributes (and bipartite and
setA_type columns for bipartite networks) |
net60_nodes.csv |
Physical node attributes: node_name,
node_type, plus any extras that are constant across
layers |
net60_state_nodes.csv |
Per-(layer, node) attributes such as abundance or module membership — written only when such attributes exist in the multilayer object |
The directed flag is not stored in the CSV files. You
specify it in the visualizer’s CSV import dialog at load time.
To import the CSV files, open the visualizer, click Import
CSV, select your three (or four) files, and confirm the
directed setting.
The visualizer is also available as a standalone web app at https://mira.ecomplab.com/ — no R session required. Export your network to JSON or CSV from R, then upload it there to share or explore it in any browser.