# 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 = )` 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()
Run the code above in your browser using DataLab