class: center, middle, inverse, title-slide # Xaringan ## A Theme for Northern Illinois University ### Christopher B. Goodman ###
School of Public & Global Affairs
Northern Illinois University --- ## Installing
The **xaringan** package is on CRAN, but I recommend installing the development release from
```r devtools::install_github('yihui/xaringan') ``` .pull-left[ You will also need two other CSS files for the custom Northern Illinois University styling: - `niu-fonts.css` - `niu.css` ] .pull-right[ If you want the University Logo to show up on the title slide, you'll also need - `NIU_horz_3Clr.png` ] These are available in the assets folder of the GitHub code repository [
`cbgoodman/niu_xaringan`](http://github.com/cbgoodman/niu_xaringan/assets) To make things easy to get started, I recommend downloading a copy of the `niu_xaringan` repo [
](https://github.com/cbgoodman/niu_xaringan/archive/master.zip) and make changes to the template. --- ## Content boxes
.content-box-blue[This is a `.content-box-blue[]` chunk. ] -- If you have just a few words, it only highlights the words: .content-box-army[`.content-box-army[]`] .content-box-yellow[`.content-box-yellow[]`] .content-box-red[`.content-box-red[]`] .content-box-purple[`.content-box-purple[]`] -- If the text includes a new line character, you get a 100% width box. I've used `.columns-2[]` it's 100% of the column width. .columns-2[ .content-box-gray[ `.content-box-gray[]` ] .content-box-green[ `.content-box-green[]` ] ] --- ## Quotes
.small[ We can include **block quotes** using<br> `<blockquote>Quote goes here</blockquote>` or<br> `> Quote goes here` ] .pull-left[ <blockquote> Statistics is the grammar of science. .right[-- <cite>Karl Pearson</cite>] </blockquote> > Quote quote ] .pull-right[.small[ ``` <blockquote> Statistics is the grammar of science. .right[-- <cite>Karl Pearson</cite>] </blockquote> > Quote quote ``` ]] --- ## Scrolling R output .scroll-output[ I tend to think it's best to format the slide such that everything you want to show is visible, however there can be times when the R output is extensive, and it's not important that the whole lot is printable (i.e. won't appear on the pdf version of the slides), but you might want to be able to scroll down interactively during the presentation. This can be done using the `.scroll-output[]` class. ```r step(lm(Fertility~.,data = swiss)) ``` ``` ## Start: AIC=190.69 ## Fertility ~ Agriculture + Examination + Education + Catholic + ## Infant.Mortality ## ## Df Sum of Sq RSS AIC ## - Examination 1 53.03 2158.1 189.86 ## <none> 2105.0 190.69 ## - Agriculture 1 307.72 2412.8 195.10 ## - Infant.Mortality 1 408.75 2513.8 197.03 ## - Catholic 1 447.71 2552.8 197.75 ## - Education 1 1162.56 3267.6 209.36 ## ## Step: AIC=189.86 ## Fertility ~ Agriculture + Education + Catholic + Infant.Mortality ## ## Df Sum of Sq RSS AIC ## <none> 2158.1 189.86 ## - Agriculture 1 264.18 2422.2 193.29 ## - Infant.Mortality 1 409.81 2567.9 196.03 ## - Catholic 1 956.57 3114.6 205.10 ## - Education 1 2249.97 4408.0 221.43 ``` ``` ## ## Call: ## lm(formula = Fertility ~ Agriculture + Education + Catholic + ## Infant.Mortality, data = swiss) ## ## Coefficients: ## (Intercept) Agriculture Education Catholic ## 62.1013 -0.1546 -0.9803 0.1247 ## Infant.Mortality ## 1.0784 ``` ] --- ## Scrolling R output If you just want a section of the output to be scrollable (not the whole page). You need to define how many lines you want the "box" to show. There are classes for `.scroll-box-8[]` for 8 lines, `.scroll-box-10[]` for 10 lines, ... , `.scroll-box-20[]` for 20 lines. .pull-left[ `.scroll-box-8[]` .scroll-box-8[ ```r swiss[,1:3] ``` ``` ## Fertility Agriculture Examination ## Courtelary 80.2 17.0 15 ## Delemont 83.1 45.1 6 ## Franches-Mnt 92.5 39.7 5 ## Moutier 85.8 36.5 12 ## Neuveville 76.9 43.5 17 ## Porrentruy 76.1 35.3 9 ## Broye 83.8 70.2 16 ## Glane 92.4 67.8 14 ## Gruyere 82.4 53.3 12 ## Sarine 82.9 45.2 16 ## Veveyse 87.1 64.5 14 ## Aigle 64.1 62.0 21 ## Aubonne 66.9 67.5 14 ## Avenches 68.9 60.7 19 ## Cossonay 61.7 69.3 22 ## Echallens 68.3 72.6 18 ## Grandson 71.7 34.0 17 ## Lausanne 55.7 19.4 26 ## La Vallee 54.3 15.2 31 ## Lavaux 65.1 73.0 19 ## Morges 65.5 59.8 22 ## Moudon 65.0 55.1 14 ## Nyone 56.6 50.9 22 ## Orbe 57.4 54.1 20 ## Oron 72.5 71.2 12 ## Payerne 74.2 58.1 14 ## Paysd'enhaut 72.0 63.5 6 ## Rolle 60.5 60.8 16 ## Vevey 58.3 26.8 25 ## Yverdon 65.4 49.5 15 ## Conthey 75.5 85.9 3 ## Entremont 69.3 84.9 7 ## Herens 77.3 89.7 5 ## Martigwy 70.5 78.2 12 ## Monthey 79.4 64.9 7 ## St Maurice 65.0 75.9 9 ## Sierre 92.2 84.6 3 ## Sion 79.3 63.1 13 ## Boudry 70.4 38.4 26 ## La Chauxdfnd 65.7 7.7 29 ## Le Locle 72.7 16.7 22 ## Neuchatel 64.4 17.6 35 ## Val de Ruz 77.6 37.6 15 ## ValdeTravers 67.6 18.7 25 ## V. De Geneve 35.0 1.2 37 ## Rive Droite 44.7 46.6 16 ## Rive Gauche 42.8 27.7 22 ``` ]] .pull-right[ `.scroll-box-14[]` .scroll-box-14[ ```r swiss[,1:3] ``` ``` ## Fertility Agriculture Examination ## Courtelary 80.2 17.0 15 ## Delemont 83.1 45.1 6 ## Franches-Mnt 92.5 39.7 5 ## Moutier 85.8 36.5 12 ## Neuveville 76.9 43.5 17 ## Porrentruy 76.1 35.3 9 ## Broye 83.8 70.2 16 ## Glane 92.4 67.8 14 ## Gruyere 82.4 53.3 12 ## Sarine 82.9 45.2 16 ## Veveyse 87.1 64.5 14 ## Aigle 64.1 62.0 21 ## Aubonne 66.9 67.5 14 ## Avenches 68.9 60.7 19 ## Cossonay 61.7 69.3 22 ## Echallens 68.3 72.6 18 ## Grandson 71.7 34.0 17 ## Lausanne 55.7 19.4 26 ## La Vallee 54.3 15.2 31 ## Lavaux 65.1 73.0 19 ## Morges 65.5 59.8 22 ## Moudon 65.0 55.1 14 ## Nyone 56.6 50.9 22 ## Orbe 57.4 54.1 20 ## Oron 72.5 71.2 12 ## Payerne 74.2 58.1 14 ## Paysd'enhaut 72.0 63.5 6 ## Rolle 60.5 60.8 16 ## Vevey 58.3 26.8 25 ## Yverdon 65.4 49.5 15 ## Conthey 75.5 85.9 3 ## Entremont 69.3 84.9 7 ## Herens 77.3 89.7 5 ## Martigwy 70.5 78.2 12 ## Monthey 79.4 64.9 7 ## St Maurice 65.0 75.9 9 ## Sierre 92.2 84.6 3 ## Sion 79.3 63.1 13 ## Boudry 70.4 38.4 26 ## La Chauxdfnd 65.7 7.7 29 ## Le Locle 72.7 16.7 22 ## Neuchatel 64.4 17.6 35 ## Val de Ruz 77.6 37.6 15 ## ValdeTravers 67.6 18.7 25 ## V. De Geneve 35.0 1.2 37 ## Rive Droite 44.7 46.6 16 ## Rive Gauche 42.8 27.7 22 ``` ]] --- ## Lists, increments and footnotes
.pull-left[ - Unordered lists<sup>1</sup> - can be created using "-" - and they can be nested using 2 or 4 space.fn[2] - deep nested - original nesting level ### Ordered list 1. one 2. two 3. three ] .footnote[ [1] Footnotes are not automatic. In the text use `<sup>1</sup>` or `.fn[1]` [2] At the end of the slide `.footnote[[1] Text associated with footnote 1.]` ] -- .pull-right[ To get an incremental slide use two dashes `--` on a new line with no trailing white space. If the dashes aren't on their own line or there's a white space after it won't work. .font80[.content-box-purple[ The two dash increments don't work inside class calls. For example, you can't have an increment in a `.pull-right[...]` block or in a `.columns-2[...]` block as the dashes are not considered to be special in the markdown processing when they're inside one of these blocks. ]] ] --- ## Icons
Perhaps the easiest way to include icons in your xaringan presentations is through the **icon** package. The **icon** package lets you include [font awesome](http://fontawesome.io), [academicons](http://jpswalsh.github.io/academicons/) and [ionicons](http://ionicons.com) into R Markdown documents. It's not yet on CRAN, so install it using ```r devtools::install_github("ropenscilabs/icon") ``` -- .pull-left[ ```r icon::fa("rocket") ```
```r icon::fa("spinner", size = 2, animate = "spin") ```
] -- .pull-right[ Inline expressions also work.
created using `` `r icon::fa("bell")` `` <br> For more info see [the
repo](https://github.com/ropenscilabs/icon). ] --- ## Data tables
.font80[ ```r library("DT"); library("dplyr") iris %>% DT::datatable(class = "compact", rownames = FALSE, extensions = "Buttons", options = list(dom = 'tBp', buttons = c("csv","excel"), pageLength = 8)) %>% DT::formatRound(1:4, digits = 1) ```
] --- ## FAQ
<blockquote> How do I start a new slide? </blockquote> Using three dashes at the start of a new line <code>---</code> -- <blockquote> I have three dashes but it's not starting a new slide. </blockquote> The three dashes need to be on their own line with **no spaces after them** -- <blockquote> I'm giving my presentation but the text is too small. HELP! </blockquote> By default remark.js disables browser based zooming. I've found and modified a hack to re-enable it, but it's not perfect. [`remark-zoom.js`](https://github.com/William-Yeh/remark-zoom) I'm also open to increasing the default font size - need to test it out on a range of displays. --- class: center, middle # Text adjustments It is also possible to change the .blue[color] of any text by using `.color[text here]` -- For example `.grey[grey]` will make text .grey[grey]. -- We can do this with white, .brand-red[NIU master brand red], .brand-blue[NIU master brand blue], .brand-yellow[NIU master brand yellow], .brand-teal[NIU master brand teal], .brand-grey[NIU master brand grey], .black[black], .red[red], .blue[blue], .green[green], .yellow[yellow], .orange[orange], .purple[purple], .grey[grey]. -- To make text stand out we can use standard markdown `**text**` like **this** or `.bold[this]` .bold[this]. Or italics using `_italic_` _italic_. You can string together these formats, e.g. `.blue[.bold[...]]` to get .blue[.bold[blue and bold text]]. -- .left[.footnote[The text on this slide is centered and in the middle of the slide because the slide began with: ``` --- class: center, middle ``` ]] --- class: niu-yellow ## Two columns!
.pull-left[ ### Some things on the left 1. List of things; 1. Plain Markdown; 1. blah blah; and 1. Plain Markdown ] -- .pull-right[ ### and other things on the right We do this by using the `.pull-left[]` and `.pull-right[]` commands. Just put any text inside the brackets and you're good to go ] Code below (or above) these two has no problem extending the full width of the slide. .footnote[The background of this slide is NIU Yellow because the slide began with: ``` --- class: niu-yellow ``` ] --- ## R code and highlighting
.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. ] --- ## R code and plot output
```r library(tidyverse) cars %>% ggplot(aes(x = dist, y = speed)) + geom_point() + * geom_smooth(method = 'lm', # highlighted using {{... formula = y ~ poly(x, 2))}} + theme_bw(base_size = 24) + labs(y = "Speed (mph)", x = "Stopping distance (ft)") ``` <img src="light_files/figure-html/unnamed-chunk-9-1.png" width="864" style="display: block; margin: auto;" /> --- class: middle, bottom background-image: url("assets/NIU_horz_3Clr.png") background-size: 50% background-position: 90% 10% This slide starts with ``` --- class: middle, bottom background-image: url("assets/NIU_horz_3Clr.png") background-size: 50% background-position: 90% 10% ``` If you want the background image to take up the full slide use ``` --- class: middle, bottom background-image: url("assets/NIU_horz_3Clr.png") *background-size: contain *background-position: 50% 50% ``` --- class: segue # Next section .left[.footnote[ ``` --- class: segue ``` ]] --- class: segue-teal # Next section .left[.footnote[ ``` --- class: segue-teal ``` ]] --- class: segue-yellow background-image: url("assets/NIU_horz_white.png") background-size: 20% background-position: 95% 95% # Next section .left[.footnote[ ``` --- class: segue-yellow background-image: url("assets/NIU_horz_white.png") background-size: 20% background-position: 95% 95% ``` ]] --- ## Font sizes .pull-left[ .pull-left[ .font10[.font10] .font20[.font20] .font30[.font30] .font40[.font40] .font50[.font50] .font60[.font60] .font70[.font70] .font80[.font80] .font90[.font90] Standard .font110[.font110] .font120[.font120] .font130[.font130] .font140[.font140] .font150[.font150] .font160[.font160] .font170[.font170] .font180[.font180] .font190[.font190] .font200[.font200] ] .pull-right[ .code10[`.code10[]`] .code20[`.code20[]`] .code30[`.code30[]`] .code40[`.code40[]`] .code50[`.code50[]`] .code60[`.code60[]`] .code70[`.code70[]`] .code80[`.code80[]`] .code90[`.code90[]`] `standard` .code110[`.code110[]`] .code120[`.code120[]`] .code130[`.code130[]`] .code140[`.code140[]`] .code150[`.code150[]`] .code160[`.code160[]`] .code170[`.code170[]`] .code180[`.code180[]`] .code190[`.code190[]`] .code200[`.code200[]`] ] ] .pull-right[ I've also enabled an alternate approach, that operates on all text: inline code, code chunks and regular text. .Large[.Large `.Large[]` 144%] .large[.large `.large[]` 120%] .small[.small `.small[]` 90%] .footnotesize[.footnotesize `.footnotesize[]` 80%] .scriptsize[.scriptsize `.scriptsize[]` 70%] .tiny[.tiny `.tiny[]` 60%] ] --- ## Font sizes This is normal sized and coloured text. With a normal size code and output: ```r rnorm(2) ``` ``` ## [1] -1.445464 -1.495882 ``` .blue[.small[This blue text is in a `.blue[.small[...]]` chunk. Everything is shrunk to 90% including the `inline code` as well as code chunks and their output: ```r rnorm(2) ``` ``` ## [1] 0.5479388 1.2786013 ``` ]] --- class: columns-2 ## Equations MathJax is supported out of the box. You can put inline equations inside dollar signs, e.g. `$\alpha + \beta$` renders as `\(\alpha + \beta\)`. Display style works with double dollar signs: <span>`$`</span><span>`$`</span>`\bar{X} = \frac{1}{n} \sum_{i=1}^n X_i`<span>`$`</span><span>`$`</span> `$$\bar{X} = \frac{1}{n}\sum_{i=1}^n X_i$$` For multi-line equations you can use <span>`\`</span>`begin{align} ... `</span>`\`</span>`end{align}` `\begin{align} \bar{X} & = X_1 + X_2 + \ldots + X_n \nonumber \\ & = \frac{1}{n}\sum_{i=1}^nX_i \label{good-eq} \end{align}` Note the equation number! We can reference it in the usual way, using <span>`\`</span>`eqref{label}`, \eqref{good-eq}, or <span>`\`</span>`ref{label}`, \ref{good-eq}. --- ## Equation numbering Equation numbering isn't part of the standard xaringan package but I've included it with the NIU theme. This is enabled with the inclusion of the `in_header` line in the YAML with reference to the file `mathjax-equation-numbers.html` which needs to be in an appropriate location. ``` output: xaringan::moon_reader: includes: * in_header: "assets/mathjax-equation-numbers.html" ``` --- ## Central limit theorem Let `\(X_{1}, X_{2},\ldots\)` be independent random variables with characteristic functions `\(\phi_{1},\phi_{2},\ldots\)` and distribution functions `\(F_{1},F_{2},\ldots\)` and let `\(\mathbb{E} X_{i}=0\)` and `\(\mathbb{E} X_{i}^{2}=\sigma_{i}^{2}<\infty\)`, `\(i=1,2,\ldots\)`. Write `\(S_{n} = \sum_{i=1}^{n}X_{i}\)` and `\(s_{n}=\textrm{Var}(S_{n}) = \sum_{i=1}^{n}\sigma^{2}_{i}\)`. Let `\begin{align} L_{n}(\varepsilon) & = s^{-2}_{n}\sum_{i=1}^{n}\mathbb{E}\big[ X_{i}^{2}\mathbb{I}\big(|X_{i}|>\varepsilon s_{n}\big)\big] \nonumber \\ & = s_{n}^{-2}\sum_{i=1}^{n}\int_{|x|>\varepsilon s_{n}}x^{2}\operatorname{d}F_{n}(x) \end{align}` The _Lindeberg condition_ states: `$$\begin{equation}\text{for all } \varepsilon>0,\ L_{n}(\varepsilon)\rightarrow0 \text{ as }n\rightarrow\infty.\label{LindCond}\end{equation}$$` If `\(\mathbb{E}|X_{1}|^{3}<\infty\)` and `\(s_{n}^{-3}\sum_{i=1}^{n}\mathbb{E}|X_{i}^{3}|\rightarrow 0\)` as `\(n\rightarrow\infty\)` then Lindeberg's condition holds. This condition under which the Lindeberg's condition holds is known as Liapounov's condition \eqref{LindCond}. --- # Tables .pull-left[ - Tables are centered by default in **xaringan**. - We can override this using `.pull-left[]` and `.pull-right[]` | This | is | a | table | | :---- | :-- | -----: | :----------: | | It is | now | pulled | to the left | | 12 | 34 | 56 | 78 | ] .pull-right[ ```r knitr::kable(iris[1:10, 1:4], format = "html") ``` .small[ <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> </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> </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> </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> </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> </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> </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> </tr> <tr> <td style="text-align:right;"> 4.6 </td> <td style="text-align:right;"> 3.4 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.3 </td> </tr> <tr> <td style="text-align:right;"> 5.0 </td> <td style="text-align:right;"> 3.4 </td> <td style="text-align:right;"> 1.5 </td> <td style="text-align:right;"> 0.2 </td> </tr> <tr> <td style="text-align:right;"> 4.4 </td> <td style="text-align:right;"> 2.9 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> </tr> <tr> <td style="text-align:right;"> 4.9 </td> <td style="text-align:right;"> 3.1 </td> <td style="text-align:right;"> 1.5 </td> <td style="text-align:right;"> 0.1 </td> </tr> </tbody> </table> ] ] --- class: title-slide-final, middle background-image: url(assets/NIU_horz_white.png) background-size: 260px background-position: 5% 5% ## Thanks! | | | | :------------------------------------------------------------------------ | :-------------------- | | <a href="mailto:cgoodman@niu.edu">.white[
] | cgoodman@niu.edu | | <a href="https://www.cgoodman.com">.white[
] | cgoodman.com | | <a href="https://twitter.com/cbgoodman">.white[
] | @cbgoodman | | <a href="https://github.com/cbgoodman">.white[
] | cbgoodman |