Skip to content

tinytheme_register#608

Merged
grantmcdermott merged 10 commits into
mainfrom
theme-register
Jun 4, 2026
Merged

tinytheme_register#608
grantmcdermott merged 10 commits into
mainfrom
theme-register

Conversation

@grantmcdermott

Copy link
Copy Markdown
Owner

Closes #579

Introduces a new tinytheme_register function, which allows users to register their own custom theme(s) that can be referenced by name.

pkgload::load_all("~/Documents/Projects/tinyplot/")
#> ℹ Loading tinyplot

# Register a simple custom theme, based on "float" but now with a grid
tinytheme_register("float2", theme = "float", grid = TRUE)

# Use it persistently
tinytheme("float2")
tinyplot(1:5)

tinytheme()

# Or ephemerally
tinyplot(1:5, theme = "float2")

# Optional: unregister the theme
tinytheme_unregister("float2")

# A more elaborate, pirate-themed example
tinytheme_register(
  "pirate",
  theme = "clean",
  family = "HersheyScript",
  bg = "#f5e6c8", fg = "#3b2209",
  cex.lab = 1.5, cex.main = 1.5, cex.sub = 1.2,
  col = "#3b2209", col.axis = "#5c3a1e", col.cap = "#7a5230", 
  col.lab = "#3b2209", col.main = "#1a0f04", col.sub = "#7a5230",
  grid = TRUE, grid.col = "#c9a96e", grid.lty = "dotted",
  facet.bg = "#e8d4a8", facet.border = "#5c3a1e",
  pch = 4,
  palette.qualitative = c(
    "#8b0000", "#1a5276", "#196f3d", "#7d6608",
    "#6c3483", "#a04000", "#1b4f72", "#145a32"
  )
)
tinyplot(
  Sepal.Length ~ Petal.Length | Species, iris,
  main = "Avast, me hearties!",
  sub  = "x marks the petal",
  cap  = "Ye Olde Iris Data", 
  theme = "pirate"
)

tinytheme_unregister("pirate")

Created on 2026-06-03 with reprex v2.1.1

@zeileis

zeileis commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Very useful feature and nice pirate example! ☠️

Maybe it would be convenient to add a shortcut register argument to tinytheme() as well? Then you could do

tinytheme("float", grid = TRUE, register = "float2")

instead of

tinytheme_register("float2", theme = "float", grid = TRUE)
tinytheme("float2")

It's a trivial thing but maybe useful?

@grantmcdermott

Copy link
Copy Markdown
Owner Author

Maybe it would be convenient to add a shortcut register argument to tinytheme() as well? Then you could do

tinytheme("float", grid = TRUE, register = "float2")

Great suggestion. I've just added support + documentation for it.

@grantmcdermott grantmcdermott merged commit 08d47f7 into main Jun 4, 2026
3 checks passed
@grantmcdermott grantmcdermott deleted the theme-register branch June 4, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Named user-defined themes not allowed in main (allowed in released version)

3 participants