class: center, middle, inverse, title-slide # R-Ladies Presentation Ninja ## ⚔
with xaringan ### Alison Presmanes Hill --- class: inverse, center, middle # Keep in touch <a href="mailto:apresstats@gmail.com"><i class="fa fa-paper-plane fa-fw"></i> apresstats@gmail.com</a><br> <a href="https://apreshill.rbind.io"><i class="fa fa-link fa-fw"></i> apreshill.rbind.io</a><br> <a href="http://twitter.com/apreshill"><i class="fa fa-twitter fa-fw"></i> @apreshill</a><br> <a href="http://github.com/apreshill"><i class="fa fa-github fa-fw"></i> @apreshill</a><br> <a href="http://cslu.ohsu.edu"><i class="fa fa-map-marker fa-fw"></i> OHSU Center for Spoken Language Understanding</a> --- background-image: url("https://media.giphy.com/media/10ZkZlv7XYbNF6/giphy.gif") background-position: 50% 50% class: center, inverse # Get Started --- # Get **xaringan** Install the **xaringan** package from [Github](https://github.com/yihui/xaringan): ```r devtools::install_github("yihui/xaringan") ``` -- You are recommended to use the [RStudio IDE](https://www.rstudio.com/products/rstudio/), but you do not have to. - Create a new R Markdown document from the menu `File -> New File -> R Markdown -> From Template -> Ninja Presentation`; -- - Click the `Knit` button to compile it; -- - or use the [RStudio Addin](https://rstudio.github.io/rstudioaddins/)<sup>1</sup> "Infinite Moon Reader" to live preview the slides (every time you update and save the Rmd document, the slides will be automatically reloaded in RStudio Viewer. .footnote[ [1] See [#2](https://github.com/yihui/xaringan/issues/2) if you do not see the template or addin in RStudio. ] --- background-image: url("https://media.giphy.com/media/q1zsIXcp8N2ne/giphy.gif") background-position: 50% 50% class: center, inverse # Use a theme --- # Themes You can use some user-contributed themes. A theme typically consists of two CSS files `foo.css` and `foo-fonts.css`, where `foo` is the theme name. Below are some existing themes: ```r names(xaringan:::list_css()) ``` ``` ## [1] "default-fonts" "default" "metropolis-fonts" ## [4] "metropolis" "rladies-fonts" "rladies" ``` To use a theme, you can specify the `css` option as an array of CSS filenames (without the `.css` extensions), e.g., ```yaml output: xaringan::moon_reader: css: [default, metropolis, metropolis-fonts] ``` If you want to contribute a theme to **xaringan**, please read [this blog post](https://yihui.name/en/2017/10/xaringan-themes). --- # The R-Ladies theme You can use it in the YAML metadata, e.g.: ```yaml --- title: "A Cool R-Ladies Presentation" output: xaringan::moon_reader css: ["default", "rladies", "rladies-fonts"] nature: highlightLines: true --- ``` See the help page `?xaringan::moon_reader` for all possible options that you can use. 💜 Definitely use the `highlightLines: true` option- read on to see why! --- background-image: url("https://media.giphy.com/media/UqjSzv18agbgk/giphy.gif") background-position: 50% 50% class: center, inverse # Now we can really have fun! --- # Side by side slides .pull-left[ ![](https://media.giphy.com/media/i1hiQy3uVZ0KQ/giphy.gif) ] .pull-right[ ![](https://media.giphy.com/media/aptJIZbitjf2g/giphy.gif) ] --- # Math Expressions You can write LaTeX math expressions inside a pair of dollar signs, e.g. $\alpha+\beta$ renders `\(\alpha+\beta\)`. You can use the display style with double dollar signs: ``` $$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$$ ``` `$$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$$` Limitations: 1. The source code of a LaTeX math expression must be in one line, unless it is inside a pair of double dollar signs, in which case the starting `$$` must appear in the very beginning of a line, followed immediately by a non-space character, and the ending `$$` must be at the end of a line, led by a non-space character; 1. There should not be spaces after the opening `$` or before the closing `$`. 1. Math does not work on the title slide (see [#61](https://github.com/yihui/xaringan/issues/61) for a workaround). --- # R Code ```r # a boring regression fit = lm(dist ~ 1 + speed, data = cars) coef(summary(fit)) ``` ``` # Estimate Std. Error t value Pr(>|t|) # (Intercept) -17.579095 6.7584402 -2.601058 1.231882e-02 # speed 3.932409 0.4155128 9.463990 1.489836e-12 ``` --- # R Plots ```r library(ggplot2) ggplot(cars, aes(speed, dist)) + geom_point() ``` ![](rladies-demo-slides_files/figure-html/cars-1.svg)<!-- --> --- # Tables If you want to generate a table, make sure it is in the HTML format (instead of Markdown or other formats), e.g., ```r knitr::kable(head(iris), format = 'html') ``` <table> <thead> <tr> <th style="text-align:right;"> Sepal.Length </th> <th style="text-align:right;"> Sepal.Width </th> <th style="text-align:right;"> Petal.Length </th> <th style="text-align:right;"> Petal.Width </th> <th style="text-align:left;"> Species </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> 5.1 </td> <td style="text-align:right;"> 3.5 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.9 </td> <td style="text-align:right;"> 3.0 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.7 </td> <td style="text-align:right;"> 3.2 </td> <td style="text-align:right;"> 1.3 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.6 </td> <td style="text-align:right;"> 3.1 </td> <td style="text-align:right;"> 1.5 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 5.0 </td> <td style="text-align:right;"> 3.6 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 5.4 </td> <td style="text-align:right;"> 3.9 </td> <td style="text-align:right;"> 1.7 </td> <td style="text-align:right;"> 0.4 </td> <td style="text-align:left;"> setosa </td> </tr> </tbody> </table> --- # Highlight code - The option `highlightLines: true` of `nature` will highlight code lines that start with `*` or are wrapped in `{{ }}`; ```yaml output: xaringan::moon_reader: nature: highlightLines: true ``` See examples on the next page. --- # Highlight code .pull-left[ An example using a leading `*`: ```r if (TRUE) { ** message("Very important!") } ``` Output: ```r if (TRUE) { * message("Very important!") } ``` This is invalid R code, so it is a plain fenced code block that is not executed. ] .pull-right[ An example using `{{}}`: ```{r tidy=FALSE} if (TRUE) { *{{ message("Very important!") }} } ``` Output: ```r if (TRUE) { * message("Very important!") } ``` ``` ## Very important! ``` It is valid R code so you can run it. ] --- class: center, middle # Thanks! Slides created via the R package [**xaringan**](https://github.com/yihui/xaringan).