24  R Markdown - Documents and Presentations in R

Today we focus on using R to make presentations - a key form of communication for data visualization. Dashboards and Documents can follow!

24.1 R Markdown

R Markdown is a package that enables an authoring framework. It enables:

  • the storing and execution of R code
  • the production of quality documents in formats including HTML, PDF, MS Word, dashboards, shiny apps, journal articles, websites, and more.

24.2 Prerequisites

Install and load rmarkdown. Install plotly too cause it is cool.

install.packages('rmarkdown')
install.packages('plotly')

24.3 Resources

RMarkdown cheatsheet RMarkdown reference guide

24.4 Use RMarkdown to make a Presentation to teach how to use RMarkdown to make a Presentation

Check Box for today’s .Rmd file and knit .html slide presentation.

24.5 Exercise 1 - Create a Presentation using your Visualization Assignment Code

  1. Open File, New File, R Markdown…
  2. Select Presentation
  3. Add your name and a title
  4. Check out the template components
  5. Edit the introduction to include a sentence about the visualization you created for your last assignment.
  6. Add each of the four bullet points to the Slide with Bullets
  7. Replace the code chunks with the table and plot with the R code you used to generate your visualization, including the libraries, data download, and tidying steps. See the example code chunk below.
  8. Press the Knit button to generate a rendered HTML presentation.
library(sf)
library(leaflet)

URL.path <- 'https://raw.githubusercontent.com/RadicalResearchLLC/EDVcourse/main/CalEJ4/CalEJ.geoJSON'
SoCalEJ <- st_read(URL.path) %>% 
  st_transform("+proj=longlat +ellps=WGS84 +datum=WGS84")

palDPM <- colorNumeric(palette = 'YlOrBr', domain = SoCalEJ$DieselPM_P)

leaflet(data = SoCalEJ) %>% 
  addTiles() %>% 
  setView(lat = 33.8, lng = -117.60, zoom = 9) %>% 
  addPolygons(stroke = FALSE,
              fillColor = ~palDPM(DieselPM_P),
              fillOpacity = 0.5) %>% 
  addLegend(pal = palDPM, 
            title = 'Diesel PM (%)', 
            values = ~DieselPM_P)