Set or Reset Plot Themes for tinyplot

Description

The tinytheme function sets or resets the theme for plots created with tinyplot. Themes control the appearance of plots, such as text alignment, font styles, axis labels, and even dynamic margin adjustment to reduce whitespace.

Usage

tinytheme(
  theme = c("default", "basic", "clean", "clean2", "bw", "classic", "minimal", "ipsum",
    "dark", "tufte", "void"),
  ...
)

Arguments

theme

A character string specifying the name of the theme to apply. Themes are arranged in an approximate hierarchy, adding or subtracting elements in the order presented below. Note that several themes are dynamic, in the sense that they attempt to reduce whitespace in a way that is responsive to the length of axes labels, tick marks, etc. These dynamic plots are marked with an asterisk (*) below.

  • “default”: inherits the user’s default base graphics settings.

  • “basic”: light modification of “default”, only adding filled points, a panel background grid, and light gray background to facet titles.

  • “clean” (*): builds on “basic” by moving the subtitle above the plotting area, adding horizontal axis labels, employing tighter default plot margins and title gaps to reduce whitespace, and setting different default palettes ("Tableau 10" for discrete colors and "agSunset" for gradient colors). The first of our dynamic themes and the foundation for several derivative themes that follow below.

  • “clean2” (*): removes the plot frame (box) from “clean”,

  • “classic” (*): connects the axes in a L-shape, but removes the other top and right-hand edges of the plot frame (box). Also sets the "Okabe-Ito" palette as a default for discrete colors. Inspired by the ggplot2 theme of the same name.

  • “bw” (*): similar to “clean”, except uses thinner lines for the plot frame (box), solid grid lines, and sets the "Okabe-Ito" palette as a default for discrete colors. Inspired by the ggplot2 theme of the same name.

  • “ipsum” (*): similar to “bw”, except subtitle is italicised and axes titles are aligned to the far edges. Inspired by the hrbrthemes theme of the same name for ggplot2.

  • “minimal” (*): removes the plot frame (box) from “bw”, as well as the background for facet titles. Inspired by the ggplot2 theme of the same name.

  • “dark” (*): similar to “minimal”, but set against a dark background with foreground and a palette colours lightened for appropriate contrast.

  • “tufte”: floating axes and minimalist plot artifacts in the style of Edward Tufte.

  • “void”: switches off all axes, titles, legends, etc.

Named arguments to override specific theme settings. These arguments are passed to tpar() and take precedence over the predefined settings in the selected theme.

Details

Sets a list of graphical parameters using tpar()

To reset the theme to default settings (no customization), call tinytheme() without arguments.

Cavear emptor: Themes are a somewhat experimental feature of tinyplot. We are reasonably confident that they should work as expected for most "standard" cases. However, there may be some sharp edges. Please report any unexpected behaviour to our GitHub repo: https://github.com/grantmcdermott/tinyplot/issues

Known current limitations include:

  • Themes do not work well when legend = “top!”.

  • Themes do not play nicely with some complex plot types, particularly “spineplot” and “ridge”.

  • Dynamic margin spacing does not account for multi-line strings (e.g., axes or main titles that contain “”).

Value

The function returns nothing. It is called for its side effects.

See Also

tpar which does the heavy lifting under the hood.

Examples

library("tinyplot")


# Reusable plot function
p = function() tinyplot(
  lat ~ long | depth, data = quakes,
  main = "Earthquakes off Fiji",
  sub = "Data courtesy of the Harvard PRIM-H project"
)
p()

# Set a theme
tinytheme("bw")
p()

# Try a different theme
tinytheme("dark")
p()

# Customize the theme by overriding default settings
tinytheme("bw", fg = "green", font.main = 2, font.sub = 3, family = "Palatino")
p()

# Reset the theme
tinytheme()
p()

# Themes showcase
## We'll use a slightly more intricate plot (long y-axis labs and facets)
## to demonstrate dynamic margin adjustment etc.

thms = eval(formals(tinytheme)$theme)

for (thm in thms) {
  tinytheme(thm)
  tinyplot(
    I(Sepal.Length*1e4) ~ Petal.Length | Species, facet = "by", data = iris,
    main = "Demonstration of tinyplot themes",
    sub = paste0('tinytheme("', thm, '")')
  )
}

# Reset
tinytheme()