Converts an EMLN multilayer object to JSON and opens MiRA, the
Multilayer Interactive Rendering Application, in the default web browser,
with MiRA's default view, in the view given by mode. To describe how
the plot should look in code, use mira() instead.
Usage
plot_mira(
multilayer,
bipartite = FALSE,
setA_type = NULL,
directed = NULL,
directed_interlayer = NULL,
mode = "network",
port = 8080,
mira_path = NULL,
browser = getOption("browser"),
viewer = getOption("ggmira.viewer", FALSE)
)
plot_multilayer(
multilayer,
bipartite = FALSE,
setA_type = NULL,
directed = NULL,
directed_interlayer = NULL,
port = 8080,
mira_path = NULL,
browser = getOption("browser"),
viewer = getOption("ggmira.viewer", FALSE)
)Arguments
- multilayer
A multilayer object (created by
create_multilayer_networkorload_emln).- bipartite
Logical. Whether the network is bipartite. Defaults to
FALSE. Bipartite is not auto-detected. WhenTRUE, the nodes table must contain anode_typecolumn (ornode_group, ortype, as in the networks ofload_emln) with exactly two distinct values across the network. MiRA knows the column asnode_type, whatever its name in the data.- setA_type
Optional character. The
node_typevalue to render as Set A (top row) in MiRA's bipartite layout. By ecological convention this is the higher trophic level (e.g."pollinator","parasite","disperser"). Only used whenbipartite = TRUE.- 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
directed. Interlayer links are directed whenever intralayer links are, soFALSEhas no effect on a directed network.- mode
The view MiRA opens in:
"network"(default),"grid","map"(needslatitudeandlongitudeinnet$layers),"layer","meta"(the meta-network),"dashboard"or"data"; each with MiRA's default settings. One view per call: to see a network in two views, callplot_mira()twice. To set a view's options (grid columns, meta-network settings), usemira()withmira_mode_grid()ormira_mode_meta().- 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 (
system.file("MiRA", package = "ggmira")).- browser
Choose the specific browser to open MiRA in. Defaults to the system default via
getOption("browser"). A command that opens a page, as forbrowseURL: a browser's name where that is a command (e.g. "firefox" on Linux), or on macOS "open -a Firefox". "chrome" works on macOS too. When R is not interactive (a script), a plot opens only whenbrowseris given.- viewer
TRUEto open MiRA in RStudio's Viewer pane instead of the browser (outside RStudio, the browser opens). Defaults toFALSE, or togetOption("ggmira.viewer"): putoptions(ggmira.viewer = TRUE)in your.Rprofileto always use the pane (the option must beTRUEorFALSE; anything else is an error). Abrowsergiven in the call wins. MiRA needs room (at least 1024 x 600 pixels): maximize the pane, or click its Show in new window button to move the plot to the browser.
Value
Invisibly returns the server handle. Use
httpuv::stopServer(handle) to stop the server when done.
NULL when nothing was opened: R is not interactive (a script, R
Markdown) and browser was not given.
Details
The plot is the one MiRA shows for the same network loaded on its
website, with two differences: the legends start minimized (as for every
plot from R; mira_legends() opens them), and the map and the layer view
are fitted to the layers.
plot_multilayer() is the same function without mode (always network
mode), under the name emln uses. While emln has a function of that name
too, the package attached last provides it: after library(emln), write
ggmira::plot_multilayer(), or use plot_mira().
From MiRA back to R. Change the plot in MiRA, then click MiRA's R
button (Copy as R code, next to Save Session): it shows the mira() code
that draws the current view, starting from this network and these
arguments, to paste into a script. Not for plot_multilayer().
The function:
Converts the multilayer object to MiRA's JSON format (the same output as
emln::multilayer_to_json)Starts a local HTTP server (using
httpuv) that serves the MiRA app and the network JSONOpens 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.
MiRA loads its drawing libraries and map tiles from the web, so the plot
needs an internet connection.
plot_multilayer() replaces emln::plot_multilayer(): the same
arguments and behavior, plus viewer.
Note
MiRA 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.
See also
mira() to describe the plot in code; mira_mode for the
views; emln::load_emln, emln::multilayer_to_json
Examples
library(emln)
net <- load_emln(17)
#> Creating state node map
#> Creating extended link list with node IDs
# Open with MiRA's defaults
plot_mira(net, bipartite = TRUE, setA_type = "bird")
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.
# In another view: the meta-network, or the layers side by side
plot_mira(net, bipartite = TRUE, setA_type = "bird", mode = "meta")
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.
plot_mira(net, bipartite = TRUE, setA_type = "bird", mode = "grid")
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.
# Directed links, on another port
plot_mira(net, bipartite = TRUE, setA_type = "bird",
directed = TRUE, directed_interlayer = TRUE, port = 9000)
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.
# Another browser; a local copy of MiRA, not the bundled one
# plot_mira(net, browser = "chrome", mira_path = "~/MiRA")
# In RStudio's Viewer pane
# plot_mira(net, bipartite = TRUE, setA_type = "bird", viewer = TRUE)
# The same as plot_mira(net, bipartite = TRUE, setA_type = "bird").
# ggmira:: because emln, attached above, has a plot_multilayer() too
ggmira::plot_multilayer(net, bipartite = TRUE, setA_type = "bird")
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.
# When done, stop the servers
httpuv::stopAllServers()
