5  Sigma.js: low-level S7 API

library(rtemis.draw)

Attaching package: 'rtemis.draw'
The following object is masked from 'package:graphics':

    Axis

The high-level draw_network() covers the common cases. When you need full control — assembling a graph node-by-node, or setting every styling option explicitly — you drop to the S7 classes, exactly as you would with EChartsOption for charts. The pattern mirrors the ECharts low-level API:

  1. Build the graph from GraphNode and GraphEdge objects into a GraphModel
  2. Combine the model and styling into a SigmaOption
  3. Render with draw()

These classes are the renderer-agnostic R counterparts of the graph model used in rtemis.live.

5.1 Building a graph by hand

A GraphModel is a list of nodes, a list of edges, and a directed flag:

model <- GraphModel(
  nodes = list(
    GraphNode(id = "hub", label = "Hub", value = 5, group = "core"),
    GraphNode(id = "a",   label = "A",   value = 2, group = "core"),
    GraphNode(id = "b",   label = "B",   value = 2, group = "leaf"),
    GraphNode(id = "c",   label = "C",   value = 1, group = "leaf")
  ),
  edges = list(
    GraphEdge(source = "hub", target = "a", weight = 1.0, sign = 1),
    GraphEdge(source = "hub", target = "b", weight = 0.7, sign = 1),
    GraphEdge(source = "hub", target = "c", weight = 0.4, sign = -1),
    GraphEdge(source = "a",   target = "b", weight = 0.5, sign = 1)
  ),
  directed = FALSE
)

Each class carries the same fields as its rtemis.live TypeScript interface:

  • GraphNodeid (required), label, value (drives size), group (categorical color key).
  • GraphEdgesource, target (required), weight (thickness), sign (1/-1, color).
  • GraphModelnodes, edges, directed.

5.2 Rendering a model with draw_graph()

draw_graph() is the mid-level builder: hand it a GraphModel plus styling and it assembles the render spec and draws it.

draw_graph(model, color_by_group = TRUE, layout = "force")

5.3 The SigmaOption render spec

draw_graph() builds a SigmaOption internally — the complete, validated render spec for a Sigma.js network (the graph model plus every styling field). It is the Sigma analog of EChartsOption, and you can construct it directly and pass it to the same draw() generic:

opt <- SigmaOption(
  model           = model,
  layout          = "circular",
  color_by_group  = TRUE,
  node_size       = 16,
  edge_scale      = 5,
  edge_opacity    = 0.6,
  scale_by_degree = FALSE,
  title           = "Hand-built graph"
)

draw(opt)

draw() dispatches on the option object, so draw(SigmaOption(...)) selects the Sigma backend just as draw(EChartsOption(...)) selects ECharts. Theme handling is identical across backends: pass theme = NULL (the default) for light/dark auto-detection, a Theme object to force one, or theme = NA for none.

The fields available on SigmaOption (and as arguments to draw_network() / draw_graph()):

  • model — the GraphModel to render.
  • layout"force" (ForceAtlas2), "circular", "circlepack", or "random".
  • resolution — Louvain resolution; higher values yield more, smaller communities.
  • node_size, scale_by_degree — base node radius in pixels, and whether each node is scaled by its weighted degree.
  • edge_scale — stroke width per unit of normalized weight.
  • node_opacity, edge_opacity — transparency.
  • show_labels — node labels.
  • color_by_group, palette — color nodes by detected community, and the palette to color them with.
  • node_color — single node color when not coloring by group.
  • positive_color, negative_color, blend_edges — edge colors by sign, or each edge as the blend of its two endpoint colors.
  • title — chart title.
© 2026 E.D. Gennatas