Introduction

This document will show the basics of creating presentations using Rmarkdown in R Studio with a review of several different methods. This document will be pretty light on code, but will (hopefully) leave the user with the basic knowledge and skills necessary to create presentations from R Studio. There are many additional resources with more specific demos of particular techniques - this document is intended to introduce the user to some pre-requisite concepts that are necessary to choose a method and will (hopefully) flatten the learning curve.

What is Rmarkdown?

Rmarkdown is an R syntax that helps make documents in many different formats. In essence, you write a mixture of plain english with some different “code wrappers” to tell Rmarkdown how you want something to be interpreted. In R Studio, you simply create a new rmarkdown file, write your text/code, and select “Knit” (which runs knitr) to turn your raw text into a complete HTML or PDF document. See R Studio’s full tutorial on creating Rmarkdown HTML documents for more information.

Why not just use Powerpoint?

The BLUF here is that powerpoint creates stagnant or “dead” documents - meaning there is no interactivity with a powerpoint visualization. If you choose to use R Studio to make your presentation, anything you can create in R can be placed dynamically into your presentation! This means any fancy, interactive rCharts, Sigma, HTML Widget, etc. that you can create in R can be a living part of your presentation. With that said, if you don’t have any potentially interactive visualizations, maybe you should stick to powerpoint. I would argue, however, that if you have no possible interactive visualizations, you should review why you are using slides in the first place.

Lets review some of the advantages and disadvantages to creating presentations in R Studio vs. Powerpoint:

Advantages of Rmarkdown compared to Powerpoint

  1. Interactive visualizations - these make for much more engaging presentations
  2. More aesthetic control - not limited to Microsoft conventions
  3. Include code and code results easily and legibly
  4. Only require a browser to open - do not require Adobe, Powerpoint, or anything else
  5. Guarantees that the code you included results in the output shown
  6. Visualization options are only limited by what is possible in R (for example, try making a decent looking Sankey diagram in Excel, Word, or Powerpoint)

Disadvantages of Rmarkdown compared to Powerpoint

  1. Requires some knowledge of R and R Studio to create documents
  2. May need some HTML/CSS knowledge to control aesthetics
  3. Somewhat more difficult to edit/collaborate - the “finished” markdown can look confusing before it is knit, as it can contain some raw HTML, R, YAML, and/or CSS code.

Basically, it is somewhat harder to make your document in Rmarkdown, but it is well worth the effort if you plan to include R code, interactive visualizations, or R-specific visualizations. Additionally, if you need your output to be an HTML file, Rmarkdown can be a great choice.

Ways to make presentations in R Studio

There are many different ways to make presentations in R Studio. I am going to focus on three: slidy, ioslides, and slidify. There are also “r presentations” which use a different markdown syntax, and are (in my opinion) less useful and user friendly than the aforementioned three options. Also, there are “shiny presentations” which allow the user to embed interactive shiny objects in their presentations. This is really great, but requires a server to host the application. I will stick to the three methods that use rmarkdown syntax and create stand alone presentations.

Slidy

Slidy is both the simplest and most robust (in my experience) of the three options.

Create a presentation

To create a slidy presentation: select File/New File/R Markdown, then choose “presentation” from the left pane of the window and “slidy” from the right pane.

The default page for slidy looks like this:

The code at the top of the page is YAML - this defines some global options for your presentation as well as your title, author, and date. The line with “output: slidy_presentation” tells knitr how to interpret everything in the document when knitting to an html presentation.

Syntax

In Slidy, you separate slides with h2 headers (denoted by ‘##’). Bullets render by adding the “-” symbol followed by a space. To make a next level bullet, you must indent 2x.

You can find more information on syntax from R Studio’s R Markdown website.

Knit the presentation

Once you are finished with your presentation, select “Knit” (near the save and spell check options at the top of the script).

As you can see, this is a pretty plain slideshow. In order to make aesthetic changes, you will need to create (or find) a CSS stylesheet. For those who have no idea what that means (as I didn’t a few days ago), I will digress:

Unlike a program like Word or Powerpoint that lets you change the aesthetics of your work as you go, markdown-based documents only apply aesthetics as you knit them. In the most basic terms, when you click “knit”, the knitr package looks at what you wrote and applies some default aesthetics to get to the end result. These defaults are specified in a css file called a stylesheet. Every method of presentation/document creation using rmarkdown has a different default stylesheet.

The good news is that you can modify and create your own stylesheets to create whatever aesthetics you want. The bad news is that you must know CSS to write a stylesheet. This is not as hard as it sounds - I was able to re-build the CAA slide template in roughly 1 hour with almost no prior knowledge of CSS. With that said, our template is pretty simple, so more complicated formatting choices will take more time.

If you do choose to make a css stylesheet, place it in your working directory and specify that you want Slidy to use it in the YAML header like this:

Save/share the presentation

Knitting the presentation will open up the R Studio viewer and will save a copy of the html document in your working directory. You can now open the html file in any browser and share via email (or any other means). Here is an example slide from a Slidy presentation using a slightly modified CSS stylesheet to change font family, size, color, etc.:

Pros

Cons

ioslides

ioslides is also simple to use and looks better than Slidy out-of-the-box, but there are some potential compromises for this simplicity. Put bluntly, ioslides does more of the styling work for you at the cost of compatibility issues.

Create the presentation

This is very similar to Slidy - just select ioslides instead of Slidy:

And the default page:

Syntax

Basic syntax is the same as Slidy, though you might run into small, specific differences when knitting documents in ioslides. Just google any errors to determine if you need to adjust the syntax.

In some cases, ioslides simply may not be able to render something that would work perfectly well in Slidy. For example, any visualization that is built on the htmlwidget framework will likely not work in ioslides. You may also have some trouble with rCharts-based visualizations. This is a well known issue, but I have not found a workable solution yet - which leads me to believe that any solution would be complicated.

Knit the presentation

This is where you will notice the difference between ioslides and Slidy. After knitting ioslides, you will see a much more aesthetically pleasing presentation, complete with subtle slide transition animations. The code chunk/code output formats are also better by default in ioslide, in my opinion.

As with Slidy, you can reference a different stylesheet if you want to change the styling.

Save/share the presentation

This is all the same as in Slidy. Here is what the same slide as above looks like in ioslides:

This slide has much better aesthetics than the Slidy example and it did not require any knowledge of CSS (this is just the default stylesheet).

Pros

Cons

Slidify

Slidify has the most options and flexibility, but is complicated to use and subject to compatibility issues. This package is clearly aimed at the intermediate to advanced R community. As such, there is a full markdown tutorial available on the slidify website. I will still give some pointers below to get started (which will mirror the information on the site).

Create the presentations

The slidify package is still under development, so you will need to install it using the devtools package. If this means nothing to you, consider turning back and not using slidify until you are more comfortable with R packages and general syntax.

Here is the code to install the package (there are 2 “libraries”):

library(devtools)
install_github('slidify', 'ramnathv')
install_github('slidifyLibraries', 'ramnathv')

Now you can create a new presentation with:

author("presentation_name")

Note, if you have git installed, this will also automatically create a git repo. This is important - be careful not to accidentally push data to git that you don’t want to be publicly available.

The default page looks like:

Syntax

Immediately, you can see that the syntax is different than slidy and ioslides. There is much more involved in the YAML header. Specifically, the “framework” option gives the ability to choose from several popular CSS stylesheets. This insulates the user from having to know any CSS, but gives some good options for different formats (not an option in Slidy or ioslides). A caution: choosing different frameworks changes the way that the markdown is interpreted. This means that choosing a new framework also changes some syntax options.

Also, unlike the first two methods, you must separate slides by a blank line followed by ‘—’.

Even if your syntax is correct, like ioslides, slidify cannot render htmlwidgets visualizations. Furthermore, it is quite difficult to get slidify to render rCharts graphics. This is ironic given that these two packages share a creator. I will leave the research to you, but including rCharts involves adding references to the specific .js libraries you need to use in the YAML header. There are some examples on stackoverflow, etc. of this, but it takes some serious work. These are known issues and the authors have indicated that they are thinking about future fixes.

Knit the presentation

Again, knitting the presentation is as easy as selecting “Knit” from the top of the frame.

The default style looks similar to ioslides, but keep in mind that you can choose different frameworks as well.

Save/share the presentation

Saving and sharing with slidify is similar to the previous two options: what you have is an html file that you can easily share via email. Additionally, slidify allows you to publish your presentation (called a “deck” in slidify-speak) to the a github repository. If you have git installed, you can use the publish() function to do just that.

Pros

Cons

General tips and tricks

  1. Write straight in HTML format. This is usually picked up and translated automatically in any rmarkdown document.
    1. Use <img src='image_name.png'> to add images to your slides
    2. Surround words/phrases with <strong>yourwordhere</strong>
    3. Add line breaks with <br>
    4. Separate blocks with <p> Your Paragraph Here </p>
    5. Hyperlink with <a href="http://awebsite.com">Text that shows up</a>
    6. See this great reference for more
  2. Make/modify CSS stylesheets for more aesthetic control.
    1. Save your CSS stylesheets as templates for future presentations
    2. Search the internet for others’ stylesheets
    3. Read the default sheets and make changes to figure out what is going on
    4. Learn CSS basics here
  3. Include R code/output whenever possible, but be mindful of slide space
    1. Hide code by including ```{r,echo=FALSE} in the chunk header
    2. Show code that doesn’t run by including ```{r, eval==FALSE} in the chunk header
    3. Remember, you have to include all of your prerequisite code if you are going to create an image because rmarkdown can only look at the code in your document (not in some other environment). It is useful to just throw the pre-processing steps at the beginning with echo=FALSE. That way, you can avoid needing too many slides to go over code that is not interesting. This is NOT a best practice for documents because you want the user to be able to see all of your code, but it can be useful to save space in a presentation. I would recommend including a version of the presentation that is knit as a document, showing all of the code, that you can send out if asked.

Conclusion

Hopefully, you are convinced that creating presentations from R Studio is a powerful option, especially when you want to render R code or graphics (especially interactive graphics). You should also now see some limitations of creating presentations this way.

To wrap up, here is when I would use each of the methods described here: 1. Powerpoint: when I don’t have any interactive figures and am in a time crunch 2. Slidify: when I am not using htmlwidgets, using few different rCharts libraries, can benefit from the many frameworks/default stylesheets, and can benefit from the github tie-in. 3. ioslides: when I am in need of a quick, good looking presentation, am happy with the default ioslides format, and am not using htmlwidgets. 4. Slidy: when I am using htmlwidgets (this is my only option of the 4!), have time to make a good looking CSS stylesheet (or have a template that I already made), and have many different visuals from different rCharts libraries.

In general, I would default to Slidy, given that I have enough time to work with the aesthetics with a CSS stylesheet. In the few weeks that I have been working on this, I already have a few different CSS stylesheets that I am pretty happy about and will continue to build upon. Since Slidy is only a compromise in the aesthetics department and it is the only method that has rendered everything I have thrown at it, I think that developing CSS stylesheets for Slidy is the best way forward. With that said, slidify is under development and the rendering issues are well known by the authors, so I wouldn’t doubt that slidify will soon be the best option for more experienced R users.