tinytheme | R Documentation |
tinyplot
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.
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()
To reset the theme to default settings (no customization), call tinytheme()
without arguments.
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()
# 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()
# 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()
# 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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.