Home

R Theme Target

Overview

R kernels receive Stencila plot-* tokens and apply them to both base graphics (par()) and ggplot2 theme defaults. Lengths are converted to points, and fonts are resolved before they are sent to the kernel.

This translation happens whenever Stencila executes R code that produces plots, for example during a render:

stencila render report.qmd report.html

Theme Transfer

  • Only plot-* tokens are sent to R kernels (see lib.rs).

  • Lengths are converted to points, and font stacks are resolved to installed font families.

  • The R theme implementation lives in theme.r.

Key Mappings

Base Graphics (par())

TokensR output
--plot-backgroundpar(bg)
--plot-axis-line-colorpar(fg)
--plot-tick-colorpar(col.axis)
--plot-axis-title-colorpar(col.lab)
--plot-axis-title-weightpar(font.lab)
--plot-text-colorpar(col.main), par(col.sub)
--plot-line-widthpar(lwd)
--plot-font-familypar(family) (mapped to sans, serif, mono)
--plot-font-sizepar(ps)
--plot-axis-title-sizepar(cex.lab)
--plot-title-sizepar(cex.main)
--plot-subtitle-sizepar(cex.sub)
--plot-padding-*par(mar) (plot margins)
--plot-panel-borderpar(bty) (box type)

ggplot2 Defaults

Tokensggplot2 output
--plot-panelpanel.background
--plot-panel-borderpanel.border toggle
--plot-axis-line-color, --plot-axis-line-widthaxis.line
--plot-grid-color, --plot-grid-x-width, --plot-grid-y-widthpanel.grid.major/minor
--plot-axis-title-color, --plot-axis-title-size, --plot-axis-title-weightaxis.title.*
--plot-tick-color, --plot-tick-width, --plot-tick-sizeaxis.ticks, axis.ticks.length
--plot-font-family, --plot-font-size, --plot-text-colortext (global); plot.title, plot.subtitle size/color
--plot-title-size, --plot-subtitle-sizeplot.title, plot.subtitle
--plot-padding-*plot.margin
--plot-legend-background, --plot-legend-border-*, --plot-legend-text-color, --plot-legend-size, --plot-legend-positionlegend.background, legend.key, legend.text, legend.title, legend.position

Palettes and Scales

TokensR output
--plot-color-1 ... --plot-color-12palette() and ggplot2 discrete scales
--plot-ramp-start, --plot-ramp-endGradient for continuous scales
--plot-shape-1 ... --plot-shape-8Base point symbols and ggplot2 shape scale
--plot-line-type-1 ... --plot-line-type-6Base line types and ggplot2 linetype scale
--plot-point-opacity, --plot-point-sizeDefault point alpha/size (ggplot2)

Not Yet Mapped

Some tokens are noted in theme.r but not yet applied, including plot-grid-dash, plot-legend-gap, plot-legend-marker-size, and several interaction/animation tokens (e.g. plot-tooltip-*, plot-crosshair-*, plot-anim-*).

Plot theme presets are documented in tokens/plots.smd.

© 2026 Stencila