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

R-Ladies Presentation Ninja


with xaringan

Alison Presmanes Hill

1 / 16

Get Started

3 / 16

Get xaringan

Install the xaringan package from Github:

devtools::install_github("yihui/xaringan")
4 / 16

Get xaringan

Install the xaringan package from Github:

devtools::install_github("yihui/xaringan")

You are recommended to use the RStudio IDE, but you do not have to.

  • Create a new R Markdown document from the menu File -> New File -> R Markdown -> From Template -> Ninja Presentation;
4 / 16

Get xaringan

Install the xaringan package from Github:

devtools::install_github("yihui/xaringan")

You are recommended to use the RStudio IDE, 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;

4 / 16

Get xaringan

Install the xaringan package from Github:

devtools::install_github("yihui/xaringan")

You are recommended to use the RStudio IDE, 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 Addin1 "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.

[1] See #2 if you do not see the template or addin in RStudio.

4 / 16

Use a theme

5 / 16

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:

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.,

output:
xaringan::moon_reader:
css: [default, metropolis, metropolis-fonts]

If you want to contribute a theme to xaringan, please read this blog post.

6 / 16

The R-Ladies theme

You can use it in the YAML metadata, e.g.:

---
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!

7 / 16

Now we can really have fun!

8 / 16

Side by side slides

9 / 16

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;

  2. There should not be spaces after the opening $ or before the closing $.

  3. Math does not work on the title slide (see #61 for a workaround).

10 / 16

R Code

# 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
11 / 16

R Plots

library(ggplot2)
ggplot(cars, aes(speed, dist)) + geom_point()

12 / 16

Tables

If you want to generate a table, make sure it is in the HTML format (instead of Markdown or other formats), e.g.,

knitr::kable(head(iris), format = 'html')
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
13 / 16

Highlight code

  • The option highlightLines: true of nature will highlight code lines that start with * or are wrapped in {{ }};

    output:
    xaringan::moon_reader:
    nature:
    highlightLines: true

    See examples on the next page.

14 / 16

Highlight code

An example using a leading *:

```r
if (TRUE) {
* message("Very important!")
}
```

Output:

if (TRUE) {
message("Very important!")
}

This is invalid R code, so it is a plain fenced code block that is not executed.

An example using {{}}:

```{r tidy=FALSE}
if (TRUE) {
{{ message("Very important!") }}
}
```

Output:

if (TRUE) {
message("Very important!")
}
## Very important!

It is valid R code so you can run it.

15 / 16

Thanks!

Slides created via the R package xaringan.

16 / 16
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
Esc Back to slideshow