8  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.

8.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 when you use 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)

8.2 Forcing a theme

draw_density(penguins$body_mass, group = penguins$species, theme = theme_dark())
2026-08-18 16:38:29 Removed 2 NA values from x [density_option]
draw_density(penguins$body_mass, group = penguins$species, theme = theme_light())
2026-08-18 16:38:29 Removed 2 NA values from x [density_option]

theme = NA disables theming entirely, leaving raw ECharts defaults — useful when you intend to register your own ECharts theme on the page.

8.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:

  • Typebase_font_size, title_font_size, subtitle_font_size, axis_label_font_size, legend_font_size, tooltip_font_size, font_family.
  • Colorcolor (the categorical palette), bg_color, fg_color, title_color, subtitle_color, legend_color, axis_color, grid_color.
  • Tooltiptooltip_bg, tooltip_border_color, tooltip_color.

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
)

8.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 when you need 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(
  sort(unique(penguins$year)),
  as.integer(table(penguins$year)),
  title = "Penguins observed per year",
  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.

8.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 
   "#B1A7B3"    "#7364F2"    "#895140" 

A quick 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
)

8.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-08-18 16:38:29 Removed 2 NA values [FUN]
2026-08-18 16:38:29 Removed 2 NA values [FUN]
dat <- table(interaction(penguins$sex, penguins$species))
draw_bar(names(dat), dat, horizontal = TRUE, palette = rtemis_colors[c(2, 1)])

8.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 teal–background–orange scale when the data spans zero, sequential otherwise
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