R Markdown Examples



R Markdown Cheat Sheet learn more at rmarkdown.rstudio.com rmarkdown 0.2.50 Updated: 8/14 1. Workflow R Markdown is a format for writing reproducible, dynamic reports with R. Use it to embed R code and results into slideshows, pdfs, html documents, Word files and more. To make a report. This book showcases short, practical examples of lesser-known tips and tricks to helps users get the most out of these tools. After reading this book, you will understand how R Markdown documents are transformed from plain text and how you may customize nearly every step of this processing. For example, you will learn how to dynamically create content from R code, reference code in other.

  • R Markdown is a powerful tool because it can be used for data analysis and data science, to collaborate with others, and communicate results to decision makers. In this blog post we’ll look at some tips, tricks, and shortcuts for working with R Markdown in RStudio.
  • So, for example, you might create a style.css file and then at the top of your R markdown document you would include:- title: Tips and tricks for working with images and figures in R Markdown documents output: htmldocument: css: style.css.

The R Markdown package ships with a raft of output formats including HTML, PDF, MS Word, R package vignettes, as well as Beamer and HTML5 presentations. This isn’t the entire universe of available formats though (far from it!). R Markdown formats are fully extensible and as a result there are several R packages that provide additional formats. In this post we wanted to highlight a few of these packages, including:

  • tufte — Documents in the style of Edward Tufte

  • rticles — Formats for creating LaTeX based journal articles

  • rmdformats — Formats for creating HTML documents

We’ll also discuss how to create your own custom formats as well as re-usable document templates for existing formats.

Using Custom Formats

Custom R Markdown formats are just R functions which return a definition of the format’s behavior. For example, here’s the metadata for a document that uses the html_document format:

Markdown Template Download

When rendering, R Markdown calls the rmarkdown::html_document function to get the definition of the output format. A custom format works just the same way but is also qualified with the name of the package that contains it. For example, here’s the metadata for a document that uses the tufte_handout format:

Custom formats also typically register a template that helps you get started with using them. If you are using RStudio you can easily create a new document based on a custom format via the New R Markdown dialog:

Tufte Handouts

The tufte package includes custom formats for creating documents in the style that Edward Tufte uses in his books and handouts. Tufte’s style is known for its extensive use of sidenotes, tight integration of graphics with text, and well-set typography. Formats for both LaTeX and HTML/CSS output are provided (these are in turn based on the work in tufte-latex and tufte-css). Here’s some example output from the LaTeX format:

If you want LaTeX/PDF output, you can use the tufte_handout format for handouts and tufte_book for books. For HTML output, you use the tufte_html format. For example:

You can install the tufte package from CRAN as follows:

See the tufte package website for additional documentation on using the Tufte custom formats.

Journal Articles

The rticles package provides a suite of custom R Markdown LaTeX formats and templates for various journal article formats, including:

  • JSS articles

  • R Journal articles

  • CTeX documents

  • ACM articles

  • ACS articles

  • Elsevier journal submissions.

You can install the rticles package from CRAN as follows:

See the rticles repository for more details on using the formats included with the package. The source code of the rticles package is an excellent resource for learning how to create LaTeX based custom formats.

Amazing R Markdown Examples

rmdformats Package

Table

The rmdformats package from Julien Barnier includes three HTML based document formats that provide nice alternatives to the default html_document format that is included in the rmarkdown package. The readthedown format is inspired by the Read the docs Sphinx theme and is fully responsive, with collapsible navigation:

The html_docco and html_clean formats both provide provide automatic thumbnails for figures with lightbox display, and html_clean provides an automatic and dynamic table of contents:

You can install the rmdformats package from CRAN as follows:

See the rmdformats repository for documentation on using the readthedown, html_docco, and html_clean formats.

Creating New Formats

Hopefully checking out some of the custom formats described above has you inspired to create your very own new formats. The R Markdown website includes documentation on how to create a custom format. In addition, the source code of the tufte, rticles, and rmdformats packages provide good examples to work from.

R Markdown Powerpoint Examples

Short of creating a brand new format, it’s also possible to create a re-usable document template that shows up within the RStudio New R Markdown dialog box. This would be appropriate if an existing template met your needs but you wanted to have an easy way to create documents with a pre-set list of options and skeletal content. See the article on document templates for additional details on how to do this.

Table of Contents

R Markdown Math Formula

R Packages

  • R Markdown Custom Formats: https://blog.rstudio.org/2016/03/21/r-markdown-custom-formats/

    • tufte — Documents in the style of Edward Tufte
    • rticles — Formats for creating LaTeX based journal articles
    • rmdformats — Formats for creating HTML documents
  • markdowntemplates: A collection of alternate R markdown templates https://github.com/hrbrmstr/markdowntemplates

  • thesisdown: An updated R Markdown thesis template using the bookdown package https://github.com/ismayc/thesisdown

  • prettydoc: Creating Pretty HTML From R Markdown http://yixuan.cos.name/prettydoc/

  • rmdTemplates R package containing a collection of Rmarkdown templates https://github.com/Pakillo/rmdTemplates

  • manuscriptPackage Template for writing manuscripts as an R package https://github.com/jhollist/manuscriptPackage

  • template A template for my research projects, based on the R package structure https://github.com/cboettig/template

  • rmarkdown-website-template: Template for creating your website with R markdown. https://github.com/privefl/rmarkdown-website-template

R Markdown Beta Hat

User defined

  • Simple template for scientific manuscripts in R markdown: http://www.petrkeil.com/?p=2401
  • An R Markdown Template for Academic Manuscripts: http://svmiller.com/blog/2016/02/svm-r-markdown-manuscript/
  • rmarkdown-article-template A personal template for Rmarkdown https://github.com/danilofreire/rmarkdown-article-template
  • R Markdown template for CSUN Master Thesis: https://github.com/carlganz/CSUNtemplate
  • uiucthemes : RMarkdown Templates for UIUC Theme-Oriented Documents (e.g. UIUC Beamer) https://github.com/coatless/uiucthemes
  • ucbthesis: Latex, Knitr, and RMarkdown templates for UC Berkeley’s graduate thesis.
  • svm-r-markdown-templates: R Markdown templates for academic manuscripts, beamer presentations, and syllabi https://github.com/svmiller/svm-r-markdown-templates

Chinese

Template for creating Chinese beamer & PDF on Windows: https://github.com/BruceZhaoR/Zh-beamer