Skip to main content

32  Themes

library(rtemis.draw)

Attaching package: 'rtemis.draw'
The following object is masked from 'package:graphics':

    Axis

Theming is uniform across all three backends: theme is an argument to every draw_*() function and to the draw() generic itself, and it takes the same four kinds of value everywhere.

theme Behavior
NULL (default) Auto-detect. The widget carries both themes and the browser picks by the active color scheme.
theme_light() / theme_dark() Force one theme.
A Theme object or a plain named list Use exactly this theme.
NA No theme — the backend’s own defaults.

32.1 Auto-detection

With theme = NULL, a light and a dark theme are both serialized into the widget payload and the binding selects one at render time. That is why a chart in an IDE follows the editor’s color scheme without being told, and why charts on this page re-theme with the light/dark toggle in the navbar — Quarto’s toggle only rewrites body classes and fires no event, so the binding watches for the change itself.

draw_scatter(penguins$bill_len, penguins$flipper_len, group = penguins$species)

32.2 Forcing a theme

draw_density(penguins$body_mass, group = penguins$species, theme = theme_dark())
2026-11-18 17:29:48 Removed 2 NA values from x [distribution_samples]
draw_density(penguins$body_mass, group = penguins$species, theme = theme_light())
2026-11-18 17:29:48 Removed 2 NA values from x [distribution_samples]

theme = NA disables theming entirely, leaving raw ECharts defaults — for a page that registers its own ECharts theme.

32.3 Customizing a theme

theme_light() and theme_dark() take the same arguments and return a Theme. Most adjustments need only base_font_size, from which the title, axis, legend, and tooltip sizes are derived (title at 1.2×, everything else at 1×) unless set explicitly:

draw_bar(
  names(table(penguins$species)),
  table(penguins$species),
  theme = theme_light(base_font_size = 16, font_family = "Georgia, serif")
)

The full set of arguments:

  • Type — base_font_size, title_font_size, subtitle_font_size, axis_label_font_size, legend_font_size, tooltip_font_size, font_family.
  • Color — color (the categorical palette), bg_color, fg_color, title_color, subtitle_color, legend_color, axis_color, grid_color.
  • Tooltip — tooltip_bg, tooltip_border_color, tooltip_color.

font_family takes a family name or a CSS font stack. Unless the stack ends in a generic family such as sans-serif, the system UI font follows it as the fallback. Its default is the rtemis.font_family option, which sets the font of every rtemis plot, for example in .Rprofile:

options(rtemis.font_family = "Geist")

A widget shows the font where the viewer’s system has it installed or the page loads it. SVG export of diagrams measures labels in the font when it is installed and the ‘systemfonts’ package is available.

Set a palette on the theme and every chart drawn with it inherits it:

plasma <- theme_light(color = c("#0F6A66", "#F08904", "#BE2E5F", "#7364F2"))

draw_boxplot(
  list(
    `Bill Length` = penguins$bill_len,
    `Flipper Length` = penguins$flipper_len
  ),
  group = penguins$species,
  theme = plasma
)
2026-11-18 17:29:48 Removed 4 NA values from data [boxplot_option]

32.4 The Theme class

theme_light() and theme_dark() are constructors over the Theme S7 class, which mirrors the object ECharts accepts as the second argument to echarts.init(). Build one directly for per-component control:

custom <- Theme(
  color = rtemis_colors[c("teal", "orange", "magenta")],
  background_color = "transparent",
  text_style = TextStyle(font_family = "Helvetica", font_size = 13),
  title = list(textStyle = list(fontSize = 20, fontWeight = "normal")),
  value_axis = list(splitLine = list(lineStyle = list(color = "#E7E5E4")))
)

draw_line(
  power_generation$month,
  power_generation$gwh,
  group = power_generation$source,
  ylab = "Generation (GWh)",
  title = "Monthly generation by source",
  theme = custom
)

Its properties: color, background_color, text_style, title, legend, tooltip, line, bar, pie, scatter, category_axis, value_axis, log_axis, time_axis. The component entries take plain named lists in ECharts’ own camelCase, since they are pass-through overrides.

32.5 Colors

rtemis_colors is the package’s named categorical palette, re-exported from rtemis.core so every rtemis package resolves the same color to the same name:

rtemis_colors
        teal       orange      magenta   light_blue        green light_orange 
   "#6CA3A0"    "#F08904"    "#BE2E5F"    "#B3CFE8"    "#0F6A66"    "#FDB808" 
         red         blue      juniper         pink dark_magenta    dark_blue 
   "#EA384A"    "#466D96"    "#526551"    "#F384FF"    "#7D0830"    "#375D86" 
 light_mauve       purple   terracotta  sunset_gold 
   "#B1A7B3"    "#7364F2"    "#895140"    "#C5A267" 

A swatch: one bar per color, drawn in its own color:

draw_bar(
  names(rtemis_colors),
  rep(1, length(rtemis_colors)),
  palette = unname(rtemis_colors),
  horizontal = TRUE
)

32.5.1 Per-chart palettes

palette overrides the theme’s palette for one chart. It takes a single color or a vector, applied to series (or groups) in order:

draw_boxplot(
  penguins[, c("bill_len", "flipper_len")],
  labels = c("Bill Length", "Flipper Length"),
  palette = rtemis_colors[["magenta"]]
)
2026-11-18 17:29:49 Removed 4 NA values from data [boxplot_option]
counts <- with(penguins, table(species, sex))
by_sex <- lapply(seq_len(ncol(counts)), function(i) as.numeric(counts[, i]))
names(by_sex) <- colnames(counts)
draw_bar(
  rownames(counts),
  by_sex,
  horizontal = TRUE,
  palette = rtemis_colors[c("orange", "teal")],
  xlab = "Penguins observed"
)

32.5.2 Continuous scales

Charts that encode a quantity in color take colormap rather than palette, since what they need is a continuous ramp and not a categorical sequence:

Function Argument Accepts
draw_heatmap() colormap Vector of 2+ colors; defaults to a diverging blue–background–orange scale when the data spans zero, and to the blue or orange half when it does not, so a hue always means the same sign
draw_spectrogram() colormap A viridisLite name ("magma", "inferno", "plasma", "viridis", "cividis", "mako", "rocket", "turbo"), "diverging", or a vector of 2+ colors
draw_choropleth() colormap One of "blues", "viridis", "ylorrd", "greens", "magma", "rdbu", "rdylgn", "spectral", "brbg"

draw_network() is the mixed case: palette colors detected communities, while node_color, positive_color, and negative_color set the ungrouped node color and the two edge-sign colors.

num <- penguins[, c("bill_len", "bill_dep", "flipper_len", "body_mass")]
draw_heatmap(
  cor(num, use = "complete.obs"),
  zlim = c(-1, 1),
  colormap = c("#466D96", "#F5F5F5", "#F08904")
)
© 2026 E.D. Gennatas