R Markdown

This is an R Markdown document themed with {bslib} package. {bslib} makes it easy to customize the main colors and fonts of a html_document, flexdashboard::flex_dashboard, shiny::fluidPage(), or more generally any website that uses Bootstrap for styling. The theme parameter in the yaml front-matter of this Rmd document describes a bslib::bs_theme() object, which provides access to 100s of theming options (via its ... argument) in addition to the main options demonstrated here (e.g., bg, fg, primary, etc).

This particular example uses {bslib}’s default Bootstrap version (which, at the time of writing, is Bootstrap 5). However, if reproducibility is important, it’s recommended that you “lock-in” the version by adding version: 5 to the theme definition.

Themed Plots

When running this document with {thematic} installed, the thematic::thematic_rmd(font = "auto") effectively translates theme (CSS) settings to new global theming defaults for {ggplot2}, {lattice}, and {base} R graphics:

ggplot2

library(ggplot2)
## Warning: 套件 'ggplot2' 是用 R 版本 4.1.3 來建造的
ggplot(mpg, aes(displ, hwy)) +
  geom_point() + geom_smooth()
## Error : The fig.showtext code chunk option must be TRUE
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

lattice

lattice::show.settings()
## Error : The fig.showtext code chunk option must be TRUE

base

plot(pressure, col = thematic::thematic_get_option("accent"))
## Error : The fig.showtext code chunk option must be TRUE

library(tidyverse)
## Warning: 套件 'tidyverse' 是用 R 版本 4.1.3 來建造的
## -- Attaching packages --------------------------------------- tidyverse 1.3.2 --
## v tibble  3.1.8      v dplyr   1.0.10
## v tidyr   1.2.1      v stringr 1.4.1 
## v readr   2.1.2      v forcats 0.5.2 
## v purrr   0.3.4
## Warning: 套件 'tibble' 是用 R 版本 4.1.3 來建造的
## Warning: 套件 'tidyr' 是用 R 版本 4.1.3 來建造的
## Warning: 套件 'readr' 是用 R 版本 4.1.3 來建造的
## Warning: 套件 'purrr' 是用 R 版本 4.1.3 來建造的
## Warning: 套件 'dplyr' 是用 R 版本 4.1.3 來建造的
## Warning: 套件 'stringr' 是用 R 版本 4.1.3 來建造的
## Warning: 套件 'forcats' 是用 R 版本 4.1.3 來建造的
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
rnorm(1000) %>% hist()
## Error : The fig.showtext code chunk option must be TRUE

rnorm(1000) %>% hist(prob=T)
## Error : The fig.showtext code chunk option must be TRUE
curve(dnorm, -3, 3, add = T)