A GPU-accelerated node-link diagram for large gene/protein interaction
networks. Nodes and edges are rendered with WebGL (via sigma v3 over a
graphology graph) so tens of thousands of elements stay interactive. When
node coordinates are not supplied, a bounded ForceAtlas2 layout positions the
nodes in the browser; otherwise the supplied x/y are used. Categorical
node groups are colored from a colorblind-safe palette. Hovering a node
highlights it and its neighbors; zoom and pan use sigma's camera. In a Shiny
app, clicking a node sets input$<id>_selected to the clicked node id, and
clicking the empty canvas clears it.
Usage
network(
nodes,
edges,
layout = c("forceatlas2", "precomputed"),
iterations = 200,
default_node_color = "#7c8598",
default_edge_color = "#d6dae1",
label_threshold = 8,
default_node_size = 4,
directed = FALSE,
palette = NULL,
theme = NULL,
width = NULL,
height = NULL,
element_id = NULL
)Arguments
- nodes
A data frame of nodes. Must contain an
idcolumn (coerced to character). Optional columns:x,y(precomputed coordinates),size(node radius in px),group(categorical, mapped to a palette color) andlabel(display name; defaults toid).- edges
A data frame of edges with columns
sourceandtargetholding node ids, an optional numericweightcolumn (mapped to edge width), and an optionalcolorcolumn giving a per-edge color (elsedefault_edge_color).- layout
Either
"forceatlas2"(run a layout when coordinates are missing) or"precomputed"(require and usex/yfromnodes).- iterations
Number of ForceAtlas2 iterations (bounded internally).
- default_node_color
Fallback node color for nodes without a
group.- default_edge_color
Edge color.
- label_threshold
Minimum node size (px) for its label to render.
- default_node_size
Node radius (px) used when
sizeis absent.- directed
Draw the graph as directed, with arrowheads. When
TRUE,A -> BandB -> Aare kept as distinct edges; whenFALSE(the default) the graph is undirected and a reciprocal pair collapses to one line.- palette
Optional character vector of hex colors overriding the default categorical palette used for node groups.
- theme
Optional named list of theme overrides (colors, fonts, ...) merged over the component defaults in the browser.
NULLuses the default theme.- width, height
Widget dimensions (any valid CSS size).
- element_id
Optional explicit DOM id.
Examples
set.seed(1)
nodes <- data.frame(
id = paste0("N", 1:60),
group = sample(c("A", "B", "C"), 60, replace = TRUE)
)
edges <- data.frame(
source = paste0("N", sample(1:60, 120, replace = TRUE)),
target = paste0("N", sample(1:60, 120, replace = TRUE))
)
network(nodes, edges)