class: title-slide, left, bottom # DANL 310 Lecture 17 ---- ## **R Markdown Basics and Tables** ### Byeong-Hak Choe ### April 14, 2022 --- class: inverse, center, middle # R Markdown Basics <html><div style='float:left'></div><hr color='#EB811B' size=1px width=796px></html> --- # 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. ### <p style="color:#327ec6">R Markdown Code</p> ```r 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 <code>`r nvars`</code>; the number of observations is <code>`r nobs`</code>. ### <p style="color:#327ec6">Output</p> The number of variables is 4; the number of observations is 28,947. Roses are <span style="color: red;">red</span>, violets are <span style="color: blue;">blue</span>. --- # 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: ### <p style="color:#327ec6">R Markdown Code</p> ```r Roses are <span style="color: red;">red</span>, violets are <span style="color: blue;">blue</span>. ``` ### <p style="color:#327ec6">Output</p> Roses are <span style="color: red;">red</span>, violets are <span style="color: red;">blue</span>. --- # Spacing - To add a space between paragraphs or lines, you can use `<br>`. .pull-left[ ### <p style="color:#327ec6">R Markdown Code</p> ```r One <br> Two ``` ] .pull-right[ ### <p style="color:#327ec6">Output</p> One <br> Two ] --- # YAML - Here is an example of the YAML metadata for an HTML document from R Markdown: .pull-left[ ### <p style="color:#327ec6">R Markdown YAML Example</p> ```r 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 ``` ] .pull-right[ ### <p style="color:#327ec6"> `theme` </p> - `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). ] --- # YAML - Here is an example of the YAML metadata for an HTML document from R Markdown: .pull-left[ ### <p style="color:#327ec6">R Markdown YAML Example</p> ```r 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 ``` ] .pull-right[ ### <p style="color:#327ec6"> `highlight` </p> - `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. ] --- class: inverse, center, middle # Tables for Descriptive Statisics <html><div style='float:left'></div><hr color='#EB811B' size=1px width=796px></html>