+ - 0:00:00
Notes for current slide
Notes for next slide

DANL 310 Lecture 17


R Markdown Basics and Tables

Byeong-Hak Choe

April 14, 2022

1 / 8

R Markdown Basics


2 / 8

Code chunks and inline R code

  • You should define the object for the number in the code chunck, so that you can use that number in the narratives of the project document.

R Markdown Code

library(tidyverse)
oj <- read_csv('https://bcecon.github.io/dominick_oj.csv')
nvars <- format(round(ncol(oj), 0),
nsmall=0,
big.mark=",")
nobs <- format(round(nrow(oj), 0),
nsmall=0,
big.mark=",")

The number of variables is `r nvars`; the number of observations is `r nobs`.

Output

The number of variables is 4; the number of observations is 28,947.

Roses are red, violets are blue.

3 / 8

Font color

  • The Markdown syntax has no built-in method for changing text colors. We can use HTML syntax to change the formatting of words:

R Markdown Code

Roses are <span style="color: red;">red</span>, violets are <span style="color: blue;">blue</span>.

Output

Roses are red, violets are blue.

4 / 8

Spacing

  • To add a space between paragraphs or lines, you can use <br>.

R Markdown Code

One
<br>
Two

Output

One

Two

5 / 8

YAML

  • Here is an example of the YAML metadata for an HTML document from R Markdown:

R Markdown YAML Example

title: "TITLE_OF_YOUR_PROJECT"
subtitle: "SUBTITLE_OF_YOUR_PROJECT<br><br>"
author:
- "AUTHOR_1"
- "AUTHOR_2"
- <br>
date: "2022-04-14<br><br>"
output:
html_document:
df_print: paged
toc: true
toc_depth: 2
toc_float: true
number_sections: true
theme: united
highlight: tango

theme

  • theme specifies the Bootstrap theme to use for the page (themes are drawn from the Bootswatch theme library).

    • Valid themes include default, bootstrap, cerulean, cosmo, darkly, flatly, journal, lumen, paper, readable, sandstone, simplex, spacelab, united, and yeti.

    • Pass null for no theme (in this case you can use the css parameter to add your own styles).

6 / 8

YAML

  • Here is an example of the YAML metadata for an HTML document from R Markdown:

R Markdown YAML Example

title: "TITLE_OF_YOUR_PROJECT"
subtitle: "SUBTITLE_OF_YOUR_PROJECT<br><br>"
author:
- "AUTHOR_1"
- "AUTHOR_2"
- <br>
date: "2022-04-14<br><br>"
output:
html_document:
df_print: paged
toc: true
toc_depth: 2
toc_float: true
number_sections: true
theme: united
highlight: tango

highlight

  • highlight specifies the syntax highlighting style.

    • Supported styles include default, tango, pygments, kate, monochrome, espresso, zenburn, haddock, breezedark, and textmate.

    • Pass null to prevent syntax highlighting.

7 / 8

Tables for Descriptive Statisics


8 / 8

R Markdown Basics


2 / 8
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
oTile View: Overview of Slides
Esc Back to slideshow