5  Sigma.js: low-level S7 API

library(rtemis.draw)
.:rtemis.draw 0.3.0 🖌 aarch64-apple-darwin23

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.

© 2026 E.D. Gennatas