• Stars
    star
    242
  • Rank 167,048 (Top 4 %)
  • Language
    R
  • License
    Other
  • Created over 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Theme ggplot2, lattice, and base graphics based on a few simple settings.

thematic

R build status CRAN status Lifecycle: experimental

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.

Installation

Install the stable release of {thematic} on CRAN with:

install.packages("thematic")

Auto theming in Shiny requires {shiny} 1.5.0 or higher:

install.packages("shiny")

Auto theming in R Markdown requires {rmarkdown} 2.7 or higher:

install.packages("rmarkdown")

Using themes with custom fonts works best if you have {showtext} and/or {ragg} installed.

install.packages("showtext")
install.packages("ragg")

Overview

{thematic}โ€™s auto theming gives R plots the ability to style themselves inside Shiny (via CSS), RStudio (via RStudio themes), and R Markdown (via {bslib}).

Shiny

Call thematic_shiny() before launching a Shiny app to enable {thematic} for every plotOutput() inside the app. If no values are provided to thematic_shiny(), each plotOutput() uses the appโ€™s CSS colors to inform new R plotting defaults. If the app uses Google Fonts (and you have {showtext} and/or {ragg} installed), you may safely provide font = "auto" to thematic_shiny(), which also translates CSS fonts to R. Hereโ€™s an example with the Pacifico font:

library(shiny)
library(ggplot2)
library(thematic)
# In order for auto/custom fonts to work properly, you'll want
# either the ragg (or showtext) package installed
library(ragg)

# If you want `{ragg}` to handle the font rendering in a Shiny app
options(shiny.useragg = TRUE)

# Call thematic_shiny() prior to launching the app, to change
# R plot theming defaults for all the plots generated in the app
thematic_shiny(font = "auto")

ui <- fluidPage(
  # bslib makes it easy to customize CSS styles for things
  # rendered by the browser, like tabsetPanel()
  # https://rstudio.github.io/bslib
  theme = bslib::bs_theme(
    bg = "#002B36", fg = "#EEE8D5", primary = "#2AA198",
    # bslib also makes it easy to import CSS fonts
    base_font = bslib::font_google("Pacifico")
  ),
  tabsetPanel(
    type = "pills",
    tabPanel("ggplot", plotOutput("ggplot")),
    tabPanel("lattice", plotOutput("lattice")),
    tabPanel("base", plotOutput("base"))
  )
)

server <- function(input, output) {
  output$ggplot <- renderPlot({
    ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars), color = factor(cyl))) +
      geom_point() +
      ggrepel::geom_text_repel()
  })
  output$lattice <- renderPlot({
    lattice::show.settings()
  })
  output$base <- renderPlot({
    image(volcano, col = thematic_get_option("sequential"))
  })
}

shinyApp(ui, server)

RStudio

Call thematic_on() before generating plots inside RStudio to have all subsequent plots shown in the โ€œPlotsโ€ viewing pane to reflect your RStudio theme. Note that thematic_on() enables {thematic} for the remainder of the R session, but you can use thematic_off() to disable (or thematic_theme() for one-off use of {thematic}). Hereโ€™s an example of how {thematic} can intelligently adapt each plot to the current RStudio theme:

R Markdown

Call thematic_rmd() before generating plots inside R Markdown to have all subsequent plots within the document reflect the relevant theme. In a static (i.e., non-runtime: shiny) R Markdown context, auto-theming only works with {bslib}-powered rmarkdown::html_document() (as in the example below), but in other situations you may also provide colors and fonts explicitly to thematic_rmd().

Custom theming

By default, {thematic} attempts to detect the relevant background, foreground, and accent colors. However, you may also specify these settings more directly by providing relevant color and fonts directly to thematic_on() (or thematic_shiny()/thematic_rmd()).

library(ggplot2)
thematic::thematic_on(bg = "#222222", fg = "white", accent = "#0CE3AC", font = "Oxanium")

ggp <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars), color = factor(cyl))) +
  geom_point() +
  ggrepel::geom_text_repel()
ggp

{thematic} works by setting new global defaults that can always be overridden with plot-specific theme()-ing code:

ggp + theme(text = element_text(colour = "purple"))

To use a โ€œcompleteโ€ {ggplot2} theme with {thematic} (e.g., theme_bw(), theme_minimal(), etc), use theme_set() to set the theme globally. This way {thematic} has the opportunity to preserve the complete themeโ€™s styling semantics when changing global defaults (e.g., theme_bw() uses the same fill color for the panel and plot background, which is semantically different from the theme_gray() default):

theme_set(theme_bw())
ggp

In addition to setting new defaults for main colors and fonts, {thematic} also sets defaults for qualitative (and sequential) colorscales. See the custom themes article to learn more about how to customize those defaults.

Learn more

  • See the auto theming article to gain a more detailed understanding of how auto theming make styling R plots easier in Shiny, R Markdown, and RStudio.
  • See the custom themes article for more on {thematic}โ€™s theming options as well as how they interact with {ggplot2}, {lattice}, and {base}.
  • See the fonts article for more on using Google Fonts with {thematic}.
  • See the scoping article for more about scoping {thematic} to individual plots.

Run some examples

Below is a link to an RStudio Cloud instance with some ready to run {thematic} examples:

Code of Conduct

{thematic} is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

More Repositories

1

cheatsheets

Posit Cheat Sheets - Can also be found at https://posit.co/resources/cheatsheets/.
TeX
5,758
star
2

shiny

Easy interactive web applications with R
R
5,341
star
3

rstudio

RStudio is an integrated development environment (IDE) for R
Java
4,432
star
4

bookdown

Authoring Books and Technical Documents with R Markdown
JavaScript
3,743
star
5

rmarkdown

Dynamic Documents for R
R
2,737
star
6

gt

Easily generate information-rich, publication-quality tables from R
R
2,019
star
7

shiny-examples

JavaScript
1,959
star
8

blogdown

Create Blogs and Websites with R Markdown
R
1,724
star
9

reticulate

R Interface to Python
R
1,675
star
10

webinars

Code and slides for RStudio webinars
HTML
1,510
star
11

rticles

LaTeX Journal Article Templates for R Markdown
TeX
1,402
star
12

plumber

Turn your R code into a web API.
R
1,390
star
13

tensorflow

TensorFlow for R
R
1,328
star
14

renv

renv: Project environments for R.
R
995
star
15

pagedown

Paginate the HTML Output of R Markdown with CSS for Print
R
883
star
16

pointblank

Data quality assessment and metadata reporting for data frames and database tables
R
868
star
17

shinydashboard

Shiny Dashboarding framework
CSS
852
star
18

keras3

R Interface to Keras
R
835
star
19

flexdashboard

Easy interactive dashboards for R
JavaScript
811
star
20

leaflet

R Interface to Leaflet Maps
JavaScript
799
star
21

rmarkdown-book

R Markdown: The Definitive Guide (published by Chapman & Hall/CRC in July 2018)
RMarkdown
738
star
22

rstudio-conf

Materials for rstudio::conf
HTML
721
star
23

shiny-server

Host Shiny applications over the web.
JavaScript
712
star
24

ggvis

Interactive grammar of graphics for R
R
709
star
25

learnr

Interactive Tutorials with R Markdown
R
709
star
26

RStartHere

A guide to some of the most useful R Packages that we know about
R
662
star
27

py-shiny

Shiny for Python
Python
627
star
28

DT

R Interface to the jQuery Plug-in DataTables
JavaScript
599
star
29

rmarkdown-cookbook

R Markdown Cookbook. A range of tips and tricks to make better use of R Markdown.
RMarkdown
577
star
30

blastula

Easily send great-looking HTML email messages from R
R
547
star
31

r2d3

R Interface to D3 Visualizations
R
516
star
32

bookdown-demo

A minimal book example using bookdown
CSS
476
star
33

hex-stickers

RStudio hex stickers
R
463
star
34

bslib

Tools for theming Shiny and R Markdown via Bootstrap 3, 4, or 5.
SCSS
461
star
35

distill

Distill for R Markdown
HTML
423
star
36

packrat

Packrat is a dependency management system for R
R
394
star
37

tufte

Tufte Styles for R Markdown Documents
R
385
star
38

dygraphs

R interface to dygraphs
JavaScript
365
star
39

revealjs

R Markdown Format for reveal.js Presentations
JavaScript
316
star
40

pins-r

Pin, discover, and share resources
R
314
star
41

fontawesome

Easily insert FontAwesome icons into R Markdown docs and Shiny apps
R
294
star
42

crosstalk

Inter-htmlwidget communication for R (with and without Shiny)
JavaScript
287
star
43

pool

Object Pooling in R
R
252
star
44

tinytex-releases

Windows/macOS/Linux binaries and installation methods of TinyTeX
PowerShell
251
star
45

config

config package for R
R
247
star
46

Intro

Course materials for "Introduction to Data Science with R", a video course by RStudio and O'Reilly Media
R
234
star
47

shinytest

Automated testing for shiny apps
JavaScript
225
star
48

shinymeta

Record and expose Shiny app logic using metaprogramming
R
223
star
49

nomnoml

Sassy 'UML' Diagrams for R
JavaScript
220
star
50

shinyuieditor

A GUI for laying out a Shiny application that generates clean and human-readable UI code
JavaScript
218
star
51

httpuv

HTTP and WebSocket server package for R
C
217
star
52

htmltools

Tools for HTML generation and output
R
201
star
53

promises

A promise library for R
R
201
star
54

vetiver-r

Version, share, deploy, and monitor models
R
181
star
55

rstudioapi

Safely access RStudio's API (when available)
R
161
star
56

concept-maps

Concept maps for all things data science
HTML
161
star
57

gradethis

Tools for teachers to use with learnr
R
161
star
58

chromote

Chrome Remote Interface for R
R
155
star
59

master-the-tidyverse

Course contents for Master the Tidyverse
155
star
60

shinythemes

Themes for Shiny
R
152
star
61

ShinyDeveloperConference

Materials collected from the First Shiny Developer Conference Palo Alto, CA January 30-31 2016
HTML
152
star
62

shiny-gallery

Code and other documentation for apps in the Shiny Gallery โœจ
HTML
147
star
63

sortable

R htmlwidget for Sortable.js
R
124
star
64

reactlog

Shiny Reactivity Visualizer
JavaScript
123
star
65

r-docker

Docker images for R
Dockerfile
121
star
66

rsconnect

Publish Shiny Applications, RMarkdown Documents, Jupyter Notebooks, Plumber APIs, and more
R
120
star
67

redx

dynamic nginx configuration
Lua
118
star
68

bigdataclass

Two-day workshop that covers how to use R to interact databases and Spark
R
114
star
69

r-system-requirements

System requirements for R packages
Shell
111
star
70

shinyloadtest

Tools for load testing Shiny applications
HTML
110
star
71

shinyvalidate

Input validation package for the Shiny web framework
JavaScript
110
star
72

shinyapps

Deploy Shiny applications to ShinyApps
110
star
73

webshot2

Take screenshots of web pages from R
R
109
star
74

shinytest2

R
103
star
75

miniUI

R
102
star
76

sass

Sass compiler package for R
C++
102
star
77

keras-customer-churn

Customer Churn Shiny Application
R
99
star
78

r-builds

an opinionated environment for compiling R
Shell
95
star
79

r-manuals

A re-styled version of the R manuals
R
88
star
80

addinexamples

An R package showcasing how RStudio addins can be registered and used.
R
86
star
81

shinyapps-package-dependencies

Collection of bash scripts that install R package system dependencies
R
74
star
82

markdown

The first generation of Markdown rendering for R (born in 2012). Originally based on the C library sundown. Now based on commonmark. Note that this package is markdown, not *rmarkdown*.
R
72
star
83

webdriver

WebDriver client in R
R
69
star
84

R-Websockets

HTML 5 Websockets implementation for R
R
68
star
85

beyond-dashboard-fatigue

Materials for the RStudio webinar 'Beyond Dashboard Fatigue'
R
66
star
86

cloudml

R interface to Google Cloud Machine Learning Engine
R
65
star
87

rstudio-docker-products

Docker images for RStudio Professional Products
Shell
64
star
88

shinylive

Run Shiny on Python (compiled to wasm) in the browser
TypeScript
61
star
89

rstudio-conf-2022-program

rstudio::conf(2022, "program")
R
60
star
90

bookdown.org

Source documents to generate the bookdown.org website
R
59
star
91

vetiver-python

Version, share, deploy, and monitor models.
Python
59
star
92

education.rstudio.com

CSS
58
star
93

tfestimators

R interface to TensorFlow Estimators
R
57
star
94

connections

https://rstudio.github.io/connections/
R
56
star
95

tfprobability

R interface to TensorFlow Probability
R
54
star
96

sparkDemos

HTML
53
star
97

swagger

Swagger is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
HTML
53
star
98

shiny-incubator

Examples and ideas that don't belong in the core Shiny package and aren't officially supported.
JavaScript
53
star
99

pins-python

Python
50
star
100

leaflet.mapboxgl

Extends the R Leaflet package with a Mapbox GL JS plugin to allow easy drawing of vector tile layers.
R
50
star