Simplified theming of ggplot2, lattice, and base R graphics. In addition to providing a centralized approach to styling R graphics, thematic also enables automatic styling of R plots in Shiny, R Markdown, and RStudio.
thematic is not yet available on CRAN, but you can install it now with:
For auto theming in Shiny, you’ll need shiny v.1.5.0 or higher.
For auto theming in R Markdown, you’ll currently need an experimental version of rmarkdown:
thematic’s auto theming gives R plots the ability to style themselves inside Shiny (via CSS), R Markdown (via bootstraplib), and RStudio (via RStudio themes). For a quick example, here’s a
shiny::tabsetPanel() with custom CSS styling, but default R styling:
To add automatic coloring and fonts (i.e., the full auto theming experience) to the R plots, simply call
thematic_on(font = "auto") and re-run the application. Since the plots are generated via Shiny, they assume new defaults which are informed by the CSS styling on their HTML container (that is, notice how the R plots now reflect the styling of the
shiny::tabsetPanel()). Moreover, as long as the relevant font is a Google Font (in this case, Pacifico), thematic automatically downloads, caches, and registers font(s) with R.
Instead of relying on thematic to automatically detect colors and fonts in the plot’s container, you can also specify them directly in
thematic_shiny(): apply theme up until the next Shiny app exits. Use this over
thematic_on()in Shiny apps.
thematic_rmd(): apply theme up until the next R Markdown document exits. Use this over
thematic_on()in R Markdown documents.
thematic_with_theme(): apply theme up until the provided plot
expris evaluated. Use this to apply different themes to different plots within a Shiny app.
Below is a link to an RStudio Cloud instance with some ready to run thematic examples: