Skip to contents

This function is inspired by thematic::thematic_on(). It modifies base R graphics, lattice, and ggplot colors and fonts to match a user-specified Bootstrap theme (using _brand.yml) features. It also further modifies the appearance of plot axes and legends (see examples).

Usage

brand_on(file, font)

Arguments

file

path to _brand.yml configuration file, normally this file is auto-detected in the working tree, but may be specified here to swap branding dynamically.

font

one of _brand.yml font families (currently only base, monospace, or headings).

Value

(invisible) list of branding elements similar in structure to _brand.yml

Details

Use in combination with brand_off() to programmatically return the plotting device to its original state.

Calling brand_on() has a few side effects in that it modifies global par() parameters, ggplot theme, changes formal arguments to graphics::plot.design() and to graphics::legend().

References

brand.yml

Examples

library(ggplot2)

brand_on(font="monospace")
#> No `_brand.yml` config found in the working tree. Loaded built-in `Mel B. Labs` theme instead.

ggplot(mtcars, aes(factor(carb), mpg, fill=factor(carb))) +
  geom_col() +
  #guides(y=guide_axis(position="right")) +
  labs(
    title = "Branded plot with fonts and color palette",
    subtitle = "My very long subtitle with many units",
    caption = "My very long plot caption with many references.")


set.seed(1)
x <- runif(100, min = -5, max = 5)
y <- x ^ 3 + rnorm(100, mean = 0, sd = 5)

plot(x, y)
axes(main="Bootstrap Branded Plot", sub="Scatter plot")


plot(x, y)
axes(nx=NULL, col.sub=pal.brandl("red"),
  main="Bootstrap Branded Plot", sub="Subtitle",
  xlab="X Units", ylab="Y Units")
abline(h=0, col=pal.brand("red"), lwd=2)


brand_off()
par("fg")
#> [1] "black"