{"id":13665781,"url":"https://github.com/rstudio/thematic","last_synced_at":"2025-04-04T12:10:29.209Z","repository":{"id":40420172,"uuid":"245531951","full_name":"rstudio/thematic","owner":"rstudio","description":"Theme ggplot2, lattice, and base graphics based on a few simple settings.","archived":false,"fork":false,"pushed_at":"2024-07-29T16:33:10.000Z","size":79962,"stargazers_count":245,"open_issues_count":24,"forks_count":11,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-03-28T11:09:47.058Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://rstudio.github.io/thematic/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rstudio.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-06T23:01:11.000Z","updated_at":"2025-03-22T08:13:46.000Z","dependencies_parsed_at":"2023-01-29T01:16:27.409Z","dependency_job_id":"24f59efb-c89f-4686-b662-8506027a65d8","html_url":"https://github.com/rstudio/thematic","commit_stats":{"total_commits":324,"total_committers":6,"mean_commits":54.0,"dds":"0.021604938271604923","last_synced_commit":"8af5f8d7c3b2800cb34acf10b8b81101141d1325"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstudio%2Fthematic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstudio%2Fthematic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstudio%2Fthematic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstudio%2Fthematic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rstudio","download_url":"https://codeload.github.com/rstudio/thematic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174456,"owners_count":20896078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T06:00:50.511Z","updated_at":"2025-04-04T12:10:29.189Z","avatar_url":"https://github.com/rstudio.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput:\n  github_document:\n    keep_html: true\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nlibrary(thematic)\nknitr::opts_chunk$set(\n  message = FALSE,\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"80%\",\n  fig.align = 'center',\n  fig.width = 6,\n  fig.asp = 0.618,  # 1 / phi\n  fig.show = \"hold\",\n  fig.retina = 2\n)\nset.seed(1234)\n```\n\n# thematic \u003ca href='https://rstudio.github.io/thematic/'\u003e\u003cimg src='man/figures/logo.png' align=\"right\" height=\"138.5\" style=\"margin:10px;\" /\u003e\u003c/a\u003e\n\n\u003c!-- badges: start --\u003e\n[![R build status](https://github.com/rstudio/thematic/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rstudio/thematic)\n[![CRAN status](https://www.r-pkg.org/badges/version/thematic)](https://CRAN.R-project.org/package=thematic)\n\u003c!-- badges: end --\u003e\n\nSimplified theming of `{ggplot2}`, `{lattice}`, and `{base}` R graphics. In addition to providing a [centralized approach](https://rstudio.github.io/thematic/articles/custom.html) to styling R graphics, `{thematic}` also enables [automatic styling](https://rstudio.github.io/thematic/articles/auto.html) of R plots in Shiny, R Markdown, and RStudio.\n\n## Installation\n\nInstall the stable release of `{thematic}` on [CRAN](https://CRAN.R-project.org) with:\n\n``` r\ninstall.packages(\"thematic\")\n```\n\n[Auto theming in Shiny](https://rstudio.github.io/thematic/articles/auto.html#shiny) requires `{shiny}` 1.5.0 or higher:\n\n```r\ninstall.packages(\"shiny\")\n```\n\n[Auto theming in R Markdown](https://rstudio.github.io/thematic/articles/auto.html#rmd) requires `{rmarkdown}` 2.7 or higher:\n\n```r\ninstall.packages(\"rmarkdown\")\n```\n\nUsing themes with [custom fonts](https://rstudio.github.io/thematic/articles/fonts.html) works best if you have `{showtext}` and/or `{ragg}` installed.\n\n```r\ninstall.packages(\"showtext\")\ninstall.packages(\"ragg\")\n```\n\n## Overview\n\n`{thematic}`'s [auto theming](https://rstudio.github.io/thematic/articles/auto.html) gives R plots the ability to style themselves inside [Shiny](#shiny) (via CSS), [RStudio](#rstudio) (via [RStudio themes](https://support.posit.co/hc/en-us/articles/115011846747-Using-Themes-in-the-RStudio-IDE)), and [R Markdown](#rmarkdown) (via [`{bslib}`](https://rstudio.github.io/bslib/)).\n\n### Shiny {#shiny}\n\nCall `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](https://fonts.google.com/) (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](https://fonts.google.com/specimen/Pacifico) font:\n\n```r\nlibrary(shiny)\nlibrary(ggplot2)\nlibrary(thematic)\n# In order for auto/custom fonts to work properly, you'll want\n# either the ragg (or showtext) package installed\nlibrary(ragg)\n\n# If you want `{ragg}` to handle the font rendering in a Shiny app\noptions(shiny.useragg = TRUE)\n\n# Call thematic_shiny() prior to launching the app, to change\n# R plot theming defaults for all the plots generated in the app\nthematic_shiny(font = \"auto\")\n\nui \u003c- fluidPage(\n  # bslib makes it easy to customize CSS styles for things\n  # rendered by the browser, like tabsetPanel()\n  # https://rstudio.github.io/bslib\n  theme = bslib::bs_theme(\n    bg = \"#002B36\", fg = \"#EEE8D5\", primary = \"#2AA198\",\n    # bslib also makes it easy to import CSS fonts\n    base_font = bslib::font_google(\"Pacifico\")\n  ),\n  tabsetPanel(\n    type = \"pills\",\n    tabPanel(\"ggplot\", plotOutput(\"ggplot\")),\n    tabPanel(\"lattice\", plotOutput(\"lattice\")),\n    tabPanel(\"base\", plotOutput(\"base\"))\n  )\n)\n\nserver \u003c- function(input, output) {\n  output$ggplot \u003c- renderPlot({\n    ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars), color = factor(cyl))) +\n      geom_point() +\n      ggrepel::geom_text_repel()\n  })\n  output$lattice \u003c- renderPlot({\n    lattice::show.settings()\n  })\n  output$base \u003c- renderPlot({\n    image(volcano, col = thematic_get_option(\"sequential\"))\n  })\n}\n\nshinyApp(ui, server)\n```\n\n```{r, echo = FALSE, out.width=\"90%\"}\nknitr::include_graphics(\"man/figures/auto-before.png\")\n```\n\n```{r, echo = FALSE, out.width=\"90%\"}\nknitr::include_graphics(\"man/figures/auto-after.png\")\n```\n\n### RStudio {#rstudio}\n\nCall `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}`](https://rstudio.github.io/thematic/articles/scope.html#one-time-use)). Here's an example of how `{thematic}` can intelligently adapt each plot to the current RStudio theme:\n\n```{r, echo = FALSE, out.width=\"100%\"}\nknitr::include_graphics(\"https://i.imgur.com/Bvbdn2B.gif\")\n```\n\n\n### R Markdown {#rmarkdown}\n\nCall `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()`](https://rstudio.github.io/bslib/#r-markdown-usage) (as in the example below), but in other situations you may also [provide colors and fonts](#custom) explicitly to `thematic_rmd()`.\n\n```{r, echo = FALSE, out.width=\"100%\"}\nknitr::include_graphics(\"vignettes/html-document.svg\")\n```\n\n\n### Custom theming {#custom}\n\nBy 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()`).\n\n```{r ggrepel, warning = FALSE}\nlibrary(ggplot2)\nthematic::thematic_on(bg = \"#222222\", fg = \"white\", accent = \"#0CE3AC\", font = \"Oxanium\")\n\nggp \u003c- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars), color = factor(cyl))) +\n  geom_point() +\n  ggrepel::geom_text_repel()\nggp\n```\n\n`{thematic}` works by setting new global defaults that can always be overridden with plot-specific `theme()`-ing code:\n\n```{r ggrepel2, warning = FALSE}\nggp + theme(text = element_text(colour = \"purple\"))\n```\n\nTo 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):\n\n```{r ggrepel3, warning = FALSE}\ntheme_set(theme_bw())\nggp\n```\n\nIn addition to setting new defaults for main colors and fonts, `{thematic}` also sets defaults for `qualitative` (and `sequential`) colorscales. See the [custom themes article](https://rstudio.github.io/thematic/articles/custom.html) to learn more about how to customize those defaults.\n\n## Learn more\n\n* See the [auto theming article](https://rstudio.github.io/thematic/articles/auto.html) to gain a more detailed understanding of how auto theming make styling R plots easier in Shiny, R Markdown, and RStudio.\n* See the [custom themes article](https://rstudio.github.io/thematic/articles/custom.html) for more on `{thematic}`'s theming options as well as how they interact with `{ggplot2}`, `{lattice}`, and `{base}`.\n* See the [fonts article](https://rstudio.github.io/thematic/articles/fonts.html) for more on using Google Fonts with `{thematic}`.\n* See the [scoping article](https://rstudio.github.io/thematic/articles/scope.html) for more about scoping `{thematic}` to individual plots.\n\n## Run some examples\n\nBelow is a link to an **RStudio Cloud** instance with some ready to run `{thematic}` examples:\n\n\u003cdiv\u003e\n  \u003ca href=\"https://rstudio.cloud/project/1208127\" target=\"_blank\"\u003e\n    \u003cimg src=\"man/figures/thematic-test-drive.svg\" alt=\"RStudio Cloud Example\" height=\"80px\" style=\"display: block; margin: 0 auto;\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\n## Code of Conduct\n\n`{thematic}` is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By [contributing](https://github.com/rstudio/thematic/blob/main/CONTRIBUTING.md) to this project, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstudio%2Fthematic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frstudio%2Fthematic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstudio%2Fthematic/lists"}