Package 'ROvis.echarts'

Title: Accessible Echarts With Rijksoverheid Styling
Description: Provides accessible, Echart plots and themed visualizations with Rijksoverheid styling.
Authors: ROvis team [cre, aut]
Maintainer: ROvis team <[email protected]>
License: EUPL (>= 1.2)
Version: 0.1.0
Built: 2026-10-19 12:33:11 UTC
Source: https://github.com/rivm-syso/ROvis.echarts

Help Index


Add keyboard navigation to an echarts4r chart

Description

ro_e_keyboard_nav() attaches JavaScript keyboard event listeners to an echarts4r chart, enabling keyboard-only users to navigate data points and toggle legend series. It is designed to follow ro_e_theme() at the end of an echarts4r pipeline.

Usage

ro_e_keyboard_nav(e, series_keys = NULL, axis = NULL)

Arguments

e

An echarts4r object.

series_keys

Named character vector mapping single-letter key codes to series names, e.g. c(w = "Women", m = "Men", t = "Total"). Names must be single letters (case-insensitive); values must exactly match the series names as used in the chart. Set to NULL (default) to omit legend controls.

axis

Character. Arrow-key direction for tooltip navigation. One of "horizontal" (ArrowLeft / ArrowRight), "vertical" (ArrowUp / ArrowDown), or "both". Default NULL auto-detects from the chart orientation.

Value

The modified echarts4r object, with keyboard navigation attached via htmlwidgets::onRender().

Keyboard controls

Arrow keys: move the tooltip across data points. Direction is auto-detected from chart orientation (left/right for column and line charts; up/down for bar charts), or set explicitly via axis. Letter keys: toggle individual legend series. Controlled by series_keys; nothing is hardcoded. Pass NULL to omit legend controls.

Axis auto-detection

The function inspects the echarts4r object to determine whether echarts4r::e_flip_coords() was applied, and assigns arrow keys accordingly. Override this with the axis argument.

See Also

Other echarts4r: ro_e_build_keyboard_nav_js(), ro_e_build_onrender_js(), ro_e_detect_axis_orientation(), ro_e_keyboard_nav_axis_js(), ro_e_keyboard_nav_legend_js(), ro_e_theme(), ro_e_theme_list()

Examples

## Not run: 
library(echarts4r)

data |>
 dplyr::group_by(sex) |>
 e_charts(year) |>
 e_line(value) |>
 e_tooltip(trigger = "axis") |>
 ro_e_theme() |>
 ro_e_keyboard_nav(series_keys = c(w = "Women", m = "Men", t = "Total"))

## End(Not run)

Apply the RO echarts theme to an echarts4r object

Description

ro_e_theme() applies the Rijksoverheid (RO) visual style to an echarts4r chart. It is the echarts equivalent of ROvis.ggplot2::ro_gg_theme() and is designed to slot into any echarts4r pipeline.

The theme is generated at call time from ROvis.utils::ro_color() and ROvis.utils::ro_color_palette(). A custom accessible HTML legend is always included. The native ECharts legend is replaced automatically to meet the RO accessibility spec.

Usage

ro_e_theme(
  e,
  palette = "categorical",
  fixed_aspect = TRUE,
  font = NULL,
  renderer = "svg"
)

Arguments

e

An echarts4r object (created with echarts4r::e_charts()).

palette

Character. Palette to use for series colors. One of "categorical" (default), "gender_con", or "gender_unc". Passed to ro_color_palette().

fixed_aspect

Logical. When TRUE (default), the total element (title + chart + legend) maintains a 2:1 width-to-height ratio, and the inner plot area (grid only, excluding axis labels and legend) maintains a 3:1 width-to-height ratio. Both ratios update responsively on resize. Set to FALSE to let the chart fill whatever height its container provides (useful when embedding in a fixed-size layout or a Shiny app with explicit height).

font

NULL (default) or a character string naming a system font family. When NULL, RijksoverheidSansWebText is used if installed, otherwise Verdana. Supply a font name to override both the chart labels and the custom HTML legend. A warning is issued if the font is not found on the system.

renderer

The renderer to use. One of "svg" or "canvas". Defaults to "svg" to comply with accessibility standards.

Value

The modified echarts4r object.

RO style applied

  • Series colors from ro_color_palette() (default: "categorical").

  • Title in ro_color("lintblauw"), subtitle in ro_color("donkerblauw").

  • Axis labels and ticks in ro_color("grijs_7").

  • Horizontal grid lines (value axis); no vertical grid lines.

  • No axis line or ticks on the value axis.

  • Custom HTML legend with per-item borders and hover/hidden styles.

See Also

Other echarts4r: ro_e_build_keyboard_nav_js(), ro_e_build_onrender_js(), ro_e_detect_axis_orientation(), ro_e_keyboard_nav(), ro_e_keyboard_nav_axis_js(), ro_e_keyboard_nav_legend_js(), ro_e_theme_list()

Examples

## Not run: 
library(echarts4r)

mtcars |>
  e_charts(wt) |>
  e_scatter(mpg) |>
  ro_e_theme()

## End(Not run)