7  MapLibre: 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_choropleth() builds its data model from a data frame. When you need full control β€” assembling rows by hand, or setting every styling option explicitly β€” you drop to the S7 classes, exactly as you would with EChartsOption for charts or SigmaOption for networks. The pattern is the same across all three backends:

  1. Build the data from MapRow objects into a MapModel
  2. Combine the model and styling into a MapLibreOption
  3. Render with draw()

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

7.1 Building a model by hand

A MapModel is a list of MapRow objects plus the administrative resolution that selects the geometry, the value label, and the names of any tooltip fields. Each MapRow carries a raw location key, a numeric value, and an optional named list of extras for the tooltip.

model <- MapModel(
  rows = list(
    MapRow(location = "USA", value = 78.5, extras = list(continent = "N. America")),
    MapRow(location = "BRA", value = 75.9, extras = list(continent = "S. America")),
    MapRow(location = "FRA", value = 82.5, extras = list(continent = "Europe")),
    MapRow(location = "JPN", value = 84.6, extras = list(continent = "Asia")),
    MapRow(location = "ZAF", value = 64.9, extras = list(continent = "Africa")),
    MapRow(location = "AUS", value = 83.4, extras = list(continent = "Oceania"))
  ),
  resolution = "country",
  value_label = "Life expectancy",
  tooltip_fields = "continent"
)

The classes mirror their rtemis.live TypeScript interfaces:

  • MapRow β€” location (required raw key), value (required number), extras (named list of tooltip fields).
  • MapModel β€” rows, resolution ("country"/"state"/"county"), value_label, tooltip_fields.

7.2 The MapLibreOption render spec

MapLibreOption is the complete, validated render spec for a choropleth β€” the MapModel plus every styling field. It is the MapLibre analog of EChartsOption and SigmaOption, and you pass it to the same draw() generic:

opt <- MapLibreOption(
  model = model,
  classification = "equal",
  color_scheme = "spectral",
  num_classes = 6,
  opacity = 0.9,
  outline_width = 0.4,
  legend_position = "bottom-left"
)

draw(opt)

draw() dispatches on the option object, so draw(MapLibreOption(...)) selects the MapLibre backend just as draw(EChartsOption(...)) selects ECharts and draw(SigmaOption(...)) selects Sigma.js. Theme handling is identical across backends: theme = NULL (the default) auto-detects light/dark, a Theme object forces one, and theme = NA disables theming.

The styling fields available on MapLibreOption (and as arguments to draw_choropleth() / draw_map()):

  • classification β€” "quantile", "equal", or "jenks".
  • color_scheme β€” sequential ("blues", "viridis", "ylorrd", "greens", "magma") or diverging ("rdbu", "rdylgn", "spectral", "brbg").
  • num_classes β€” number of color classes (2–12).
  • opacity, show_boundaries, outline_width β€” fill and outline appearance.
  • show_legend, legend_position, tooltip_position, report_position β€” overlay visibility and corner anchors.
Β© 2026 E.D. Gennatas