draw() renders chart configurations and backend option objects as
interactive visualizations. It is an 'S7' generic that dispatches on the
class of option:
Usage
draw(
option,
theme = NULL,
width = NULL,
height = NULL,
element_id = NULL,
filename = NULL,
animation = NULL,
...
)Arguments
- option
ChartConfig subclass, EChartsOption, SigmaOption, MapLibreOption, PeleOption, or named list: Chart configuration or render spec to draw. All concrete chart configuration classes listed below are supported.
- theme
Optional Theme, list, or
NA: Theme override.NULLenables light/dark auto-detection;NAdisables theming. Applied to every backend.- width
Optional Character or Numeric: Widget width.
- height
Optional Character or Numeric: Widget height.
- element_id
Optional Character: Explicit element ID.
- filename
Optional Character: If provided, the widget is also written to this file via
save_drawing(). Extension determines the format (currently only.svg).- animation
Optional Logical: Whether ECharts animates the chart.
NULL(default) leaves ECharts' own default in place.FALSEdisables animation, which matters for charts with many points, where animating every interactive update is expensive. Ignored by the Sigma, MapLibre, and Pele backends, which have no ECharts animation to disable.- ...
Named arguments for the selected method. For ChartConfig subclasses,
datasupplies the data to plot; its required structure depends on the configuration class. Ifdatais omitted orNULL, the config'sdat_pathis read instead.Additional arguments are passed to the rendering backend. ECharts accepts
renderer(Character {"canvas", "svg"}) andmeta(named list of extra payload fields, used internally e.g. bydraw_heatmap()). Any other name is an error rather than a silent no-op, so a typo cannot quietly change what is drawn.Two
metafields are read by the ECharts JS binding and are part of its contract, because they need the container width, which only the browser knows:squareCells: seedraw_heatmap().aspect: a named list withratio(required grid height / grid width),widthPx(preferred grid width; the box shrinks below this only when the container is too narrow), andleftPx,rightPx,topPx,botPx(padding to reserve outside the grid). The binding solves for the grid box on render and on resize, and sets the container height to match. Use it for charts whose pixel geometry carries meaning – most often equal axis scaling, where one data unit must be the same number of pixels on both axes andratiois therefore the y range over the x range. ECharts has no equal-aspect option, and R cannot know the container width, so neither side can enforce this alone.
Details
ChartConfig subclasses -> compile the configuration with its data, then render using the corresponding backend.
EChartsOption -> 'ECharts' (
rtemis-drawwidget).SigmaOption -> 'Sigma.js' (
rtemis-graphwidget).MapLibreOption -> 'MapLibre' (
rtemis-mapwidget).PeleOption -> 'Pele' (
rtemis-diagramwidget).
A plain named list is treated as a raw 'ECharts' option.
Theme handling is uniform across backends and lives on draw(), not on the
option object: pass NULL (default) for light/dark auto-detection (from VS
Code, RStudio, or the browser's prefers-color-scheme), NA for no theme
(raw backend defaults), or a Theme / list to force one.
Chart configurations
Supported ChartConfig subclasses are A3Config, BarConfig,
BoxplotConfig, CalibrationConfig, ChoroplethConfig, ConfusionConfig,
DensityConfig, GanttConfig, HeatmapConfig, HistogramConfig,
LineConfig, MermaidConfig, NetworkConfig, PieConfig, PRConfig,
ROCConfig, SankeyConfig,
ScatterConfig, Scatter3DConfig, SignificanceConfig, SpectrogramConfig,
SurvivalConfig, and TimeSeriesConfig. Use their setup_*() functions to
create configurations, then pass the data to draw() with data = or set
dat_path on the configuration. See compile() to obtain the backend option
without rendering it.
Examples
# Render a chart configuration with data.
config <- setup_ScatterConfig(x = "wt", y = "mpg")
draw(config, data = mtcars)
# Render a backend option directly.
option <- EChartsOption(
x_axis = Axis(type = "category", data = c("Mon", "Tue", "Wed")),
y_axis = Axis(type = "value"),
series = BarSeries(data = c(120, 200, 150))
)
draw(option)