| tinytheme | R Documentation |
tinyplotThe 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.
tinytheme(
theme = c("default", "basic", "clean", "clean2", "bw", "classic", "minimal", "ipsum",
"dark", "ridge", "ridge2", "tufte", "void"),
...
)
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.
|
... |
Named arguments to override specific theme settings. These
arguments are passed to |
Sets a list of graphical parameters using tpar()
Note that themes are persistent and will be applied to all subsequent plots.
To reset the theme to default settings (no customization), call tinytheme()
without arguments. Altenatively, invoke the tinyplot(..., theme = <theme>)
argument for an ephemeral theme that is automatically reset at the end of the
plot call.
Caveat emptor: Themes are a somewhat experimental feature of tinyplot.
While we feel confident that themes should work as expected for most
"standard" cases, 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!".
Dynamic margin spacing does not account for multi-line strings (e.g., axes or main titles that contain "\n").
The function returns nothing. It is called for its side effects.
tpar which does the heavy lifting under the hood.
# 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()
# A set theme is persistent and will apply to subsequent plots
tinyplot(0:10)
# 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()
# Another custom theme example
tinytheme("bw", font.main = 2, col.axis = "darkcyan", family = "HersheyScript")
p()
# Aside: One or two specialized themes are only meant for certain plot types
tinytheme("ridge2")
tinyplot(I(cut(lat, 10)) ~ depth, data = quakes, type = "ridge")
# Reset the theme
tinytheme()
p()
# For an ephemeral theme, use `tinyplot(..., theme = <theme>)` directly
tinyplot(0:10, theme = "clean", main = "This theme is ephemeral")
tinyplot(10:0, main = "See, no more theme")
# 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,
yaxl = ",",
main = paste0('tinytheme("', thm, '")'),
sub = "A subtitle"
)
box("outer", lty = 2)
}
# Reset
tinytheme()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.