2/25/2020

This town ain’t big enough for the both of us

Why not just use Powerpoint?

I already use R for my analyses, can I use it to build slides?

…Yes you can!

What if I don’t really use R (much)

  • It does take a bit of practice
  • You’ll need to use some CSS code if you like to customize things like fonts and colors
  • You’ll need to use RMarkdown

Wait, what is Rmarkdown?

  • Just like a regular R script but allows you to ‘knit’ a final document to many different formats including:
    • pdf
    • word
    • html
    • and slides!
  • You write in a mixture of plain english and code
  • Final doc can include code and output/figures

Let’s talk about some of the advantages and disadvantages to creating presentations in R Studio vs. Powerpoint:

Advantages

  • Interactive visualizations
  • Include code and code results easily and legibly
  • Only requires a browser to open
  • The whole thing is reproducible!

You can include animated R figures!!

  • Visualization options are only limited by what is possible in R

And another!

You can show code and output!

  • Show show code, show output, or show both!
trial %>% 
  select(-ttdeath, -death, -response, -grade) %>% 
  tbl_summary(by=trt)
Characteristic Drug A, N = 981 Drug B, N = 1021
Age, yrs 46 (37, 59) 48 (39, 56)
Unknown 7 4
Marker Level, ng/mL 0.84 (0.24, 1.57) 0.52 (0.19, 1.20)
Unknown 6 4
T Stage
T1 28 (29%) 25 (25%)
T2 25 (26%) 29 (28%)
T3 22 (22%) 21 (21%)
T4 23 (23%) 27 (26%)

1 Statistics presented: median (IQR); n (%)

Disadvantages

  • Takes time to knit slides if complex (~5 minutes)
  • Takes time for your changes to be updated in the browser (another 5 minutes)
  • Requires some knowledge of R and RStudio to create documents
  • Limited slide layout and styling options
  • Some HTML/CSS knowledge to control aesthetics
  • 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.

Ok, how do I do it?

How do I tell R I want to create slides?

Specify the ioslides_presentation output format in the YAML metadata of your document:

What code do I use to separate slides?

How do I get my slides onto a web browswer?

  1. Sign into GitHub.com GitHub.com

Wait, what is GitHub again?

GitHub is a place to save your work, keeping track of changes over time. You can also make files publicly available via the GitHub website.

Then what?


  • Create a new repository in GitHub
  • Go into RStudio and create a new project FROM a GitHub repository
    • To do this, select: File>New Project>Version Control>Git>paste url from GitHub repository page
  • Note: Creating a separate RStudio project for your slides is good practice because it is publicly available



Ok, keep going…

  • New RMarkdown, select presetation instead of document (choose html ioslides)
  • Save RMarkdown as “index.html” – this is important, make sure its lowercase
  • Push them to GitHub: on the GIT tab in the upper right hand window in Rstudio
  • Select all files and commit (must commit the index.html, other items are optional)
  • Select push after commiting
  • Enter GitHub username and password

Just a few more steps…

  • Go to settings in GitHub and scroll down to “GitHub Pages”, then change Source None to Master Branch
  • Copy url above this option “Your site is ready to be published at https://github.com/ahinton-mmc/Slides
  • Click edit on main page and put the url link into the Website box, and you can add a Description

How do I share and update slides?

  • Make changes in R then Git commit/push
  • Same web link should update (but give it some time)
  • Weblink can be emailed, GitHub page can be shared

The takeaway:

If your slides are… simple, you don’t care too much about style, you want to show code, figures, and tables…

Use ioslides!

Gallery of RMarkdown Formats and Outputs

Resources