Themes

library(gglite)
p = g2(mtcars, hp ~ mpg)

Themes control the overall visual appearance of the chart. Use helpers like theme_classic(), theme_dark(), theme_light(), theme_classic_dark(), and theme_academy() to set a built-in theme.

G2 provides five built-in themes in two pairs plus one standalone:

1 Classic Theme (default)

p |> theme_classic()

2 Classic Dark Theme

p |> theme_classic_dark()

3 Light Theme

p |> theme_light()

4 Dark Theme

p |> theme_dark()

5 Academy Theme

p |> theme_academy()

6 Theme on a bar chart

df = data.frame(x = c('A', 'B', 'C', 'D'), y = c(3, 7, 2, 5))
g2(df, y ~ x, color = ~ x) |>
  theme_dark()

7 Theme on a multi-series line chart

df = data.frame(
  x = rep(1:5, 2), y = c(3, 1, 4, 1, 5, 2, 7, 1, 8, 3),
  group = rep(c('A', 'B'), each = 5)
)
g2(df, y ~ x, color = ~ group) |>
  mark_line() |>
  theme_classic_dark()