🎨 Step right into the colorful realm of R Markdown Themes! 🌸 😄
This article can be used at will if you need it. Please copy the corresponding YAML code below 👇. Enjoy! 🏄
R Markdown
R Markdown is a popular tool for creating dynamic documents that combine code, text, and visualizations. It allows you to seamlessly integrate R code and its output with narrative text to create reproducible reports, presentations, and even websites. R Markdown themes play a crucial role in customizing the appearance and style of these documents.
A theme in R Markdown determines the overall look and feel of the document, including the font styles, colors, margins, and other visual elements. It helps you create documents that are visually appealing and consistent with your personal or organizational style.
R Markdown provides a default theme, but you can easily modify it or choose from a variety of predefined themes to customize the appearance of your document. These themes are defined using CSS (Cascading Style Sheets), a popular web design language for controlling the presentation of HTML documents.
YAML Explanation
To apply a theme to your R Markdown document, you simply specify the desired theme in the YAML (YAML Ain’t Markup Language) header at the beginning of your document. The YAML header is a section where you can set various options and configurations for your document, including the theme.
To create an HTML document from R Markdown, you specify the html_document output format in the YAML metadata of your document:
---
: "This is a YAML"
title: "Type your name here"
author: "`r Sys.Date()`"
date: html_document
output---
If you want a toc or table of content in your R Markdown knit files,
your can specify toc: yes
in output format in the YAML
metadata of your document and specify the toc_float
option
to float the table of contents to the left of the main document content.
The floating table of contents will always be visible even when the
document is scrolled. For example:
---
: "This is a YAML"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output:
html_document: yes
toc:
toc_float: true
collapsed---
for more details: https://bookdown.org/yihui/rmarkdown/html-document.html#table-of-contents
Themes in R Markdown
R Markdown provides a wide range of built-in themes, such as “simplex,” “slate,” “flatly,” “darkly,” and many more. Each theme has its own unique visual characteristics, allowing you to choose a style that best suits your content or purpose. Basically, you can using R Markdown themes from base R, you don’t need for install any packages for that. But, when you want some extra. Here is some packages you can use for customize the themes.
# load library
library(rmdformats)
library(prettydoc)
library(hrbrthemes)
library(tint)
library(tufte)
Base R Theme
default
- YAML formats
---
: "This is a Default Themes YAML"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output:
html_document: yes
toc:
toc_float: true
collapsed---
- Result
cerulean
- YAML formats
---
: "This is a Cerulean Themes YAML"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output:
html_document: cerulean
theme: yes
toc:
toc_float: true
collapsed---
- Result
journal
- YAML formats
---
: "This is a Journal Themes YAML"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output:
html_document: journal
theme: yes
toc:
toc_float: true
collapsed---
- Result
flatly
- YAML formats
---
: "This is a Flatly Themes YAML"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output:
html_document: flatly
theme: yes
toc:
toc_float: true
collapsed---
- Result
united
- YAML formats
---
: "This is a United Themes YAML"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output:
html_document: united
theme: yes
toc:
toc_float: true
collapsed---
- Result
cosmo
- YAML formats
---
: "This is a Cosmo Themes YAML"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output:
html_document: cosmo
theme: yes
toc:
toc_float: true
collapsed---
- Result
simplex
- YAML formats
---
: "This is a Simplex Themes YAML"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output:
html_document: simplex
theme: yes
toc:
toc_float: true
collapsed---
- Result
prettydoc
Package Theme
cayman
The Default Theme from prettydoc
package
- YAML formats
---
: "This is a Cayman Themes YAML from `prettydoc` Package"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output::html_pretty:
prettydoc: cayman
theme: yes
toc---
- Result
leonids
- YAML formats
---
: "This is a Leonids Themes YAML from `prettydoc` Package"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output::html_pretty:
prettydoc: leonids
theme: yes
toc---
- Result
architect
- YAML formats
---
: "This is a Architect Themes YAML from `prettydoc` Package"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output::html_pretty:
prettydoc: architect
theme: yes
toc---
- Result
hpstr
- YAML formats
---
: "This is a hpstr Themes YAML from `prettydoc` Package"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output::html_pretty:
prettydoc: hpstr
theme: yes
toc---
- Result
tactile
- YAML formats
---
: "This is a Tactile Themes YAML from `prettydoc` Package"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output::html_pretty:
prettydoc: tactile
theme: yes
toc---
- Result
`rmdformats`` Package Theme
Documentation: https://cran.r-project.org/web/packages/rmdformats/index.html
html_clean
- YAML formats
---
: "This is a html_clean Themes YAML from `rmdformats` Package"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output::html_clean
rmdformats---
- Result
readthedown
- YAML formats
---
: "This is a readthedown Themes YAML from `rmdformats` Package"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output::readthedown
rmdformats---
- Result
material
- YAML formats
---
: "This is a material Themes YAML from `rmdformats` Package"
title: "Type your name here"
author: "`r Sys.Date()`"
date:
output::material
rmdformats---
- Result
tint
Package Theme
Documentation:
tintHtml
- YAML formats
---
: "This is a tintHtml Themes YAML from `tint` Package"
title: "Type your name here"
author: "`r Sys.Date()`"
date: tint::tintHtml
output---
- Result
tufte
Package Theme
Documentation: https://garrettgman.github.io/rmarkdown/tufte_handout_format.html
tufte_html
- YAML formats
---
: "This is a tufte_html Themes YAML from `tufte` Package"
title: "Type your name here"
author: "`r Sys.Date()`"
date: tufte::tufte_html
output---
- Result
CSS- Custom Your Own Theme
Additionally, if you have more advanced knowledge of CSS, you can create your own custom themes or modify existing ones. This allows you to tailor the appearance of your documents to match your specific requirements or branding guidelines. By overriding the default styles, you can customize fonts, colors, background images, and other design elements.
- css Document
A CSS (Cascading Style Sheets) document is a file that contains CSS code, which is a language used to describe the style and formatting of a document written in HTML (Hypertext Markup Language) or XML (eXtensible Markup Language).
CSS documents provide a powerful and flexible way to control the visual presentation of web pages, allowing you to define styles, layouts, colors, and other visual aspects of your website, separate from the actual content
A typical CSS document consists of a series of selectors and declarations. Selectors are used to target specific HTML elements, while declarations define the desired styles for those elements. Here’s a simple example:
h1 {-size: 1.8em;
font-weight: bolder;
font: #467d62;
color
}
h2 {-size: 1.6em;
font-weight: bolder;
font: #FB5151;
color
}
h3,h4 {-size: 1.3em;
font-weight: bolder;
font: #990000;
color }
You can make your own css in any text editor (ex: Notepad).
- YAML formats
---
: "Programming for Data Science: In-Class Material"
title: "Rany Dwi Cahyaningtyas"
author: "Vulcan: 29-31 Mei 2023"
date:
output:
html_document: assets/rany_style.css
css: paged
df_print: tango
highlight: cosmo
theme: yes
toc:
toc_float: true
collapsed: true
number_sections---
- Result
Summary
In summary, R Markdown themes enable you to control the visual aspects of your documents, making them more engaging and professional. Whether you prefer a minimalistic look or a vibrant design, R Markdown themes give you the flexibility to create documents that align with your personal style or organizational branding.