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

How to Make Slides in R

Using xaringan

Zhi Yang

2019/2/26

1 / 39

How I met xaringan Sharingan

An R user who would like to share awesome things in R

2 / 39

How I met xaringan Sharingan

An R user who would like to share awesome things in R

by showing a bunch of R code snippets without losing taste.

2 / 39

How I met xaringan Sharingan

An R user who would like to share awesome things in R

by showing a bunch of R code snippets without losing taste.

given no time nor money on formatting codes and adjusting layouts.

2 / 39

Meet xaringan Sharingan

Beautiful and concise layout

3 / 39

Meet xaringan Sharingan

Code highlighting and live demos

4 / 39

Meet xaringan Sharingan

Version control and easy distribution

5 / 39

Meet xaringan Sharingan

It animates

6 / 39

Infinite moon reader 👩‍🚀

Do you use ctrl + K to render your slides?

  • So, Are you tired from scrolling down to the page you were working on?

7 / 39

Infinite moon reader 👩‍🚀

Do you use ctrl + K to render your slides?

  • So, Are you tired from scrolling down to the page you were working on?

Turn on the Moon Reader from either the pacakge or the addins

From now on, the slides will auto-reload every time you save it

7 / 39

Infinite moon reader 👩‍🚀

8 / 39

Keyboard shortcuts

Press h or ?

9 / 39

Keyboard shortcuts

Press h or ?

m -> mirror

b -> blackout

f -> fullscreen mode

9 / 39

Keyboard shortcuts

Press h or ?

m -> mirror

b -> blackout

f -> fullscreen mode

c -> clone slideshow

p -> presenter mode

t -> restart timer

9 / 39

Themes

  • Built-in themes
names(xaringan:::list_css())
## [1] "chocolate-fonts" "chocolate" "default-fonts"
## [4] "default" "duke-blue" "fc-fonts"
## [7] "fc" "hygge-duke" "hygge"
## [10] "kunoichi" "lucy-fonts" "lucy"
## [13] "metropolis-fonts" "metropolis" "middlebury-fonts"
## [16] "middlebury" "ninjutsu" "rladies-fonts"
## [19] "rladies" "robot-fonts" "robot"
## [22] "rutgers-fonts" "rutgers" "shinobi"
## [25] "tamu-fonts" "tamu" "uo-fonts"
## [28] "uo" "uol-fonts" "uol"
10 / 39

Themes

  • Built-in themes
names(xaringan:::list_css())
## [1] "chocolate-fonts" "chocolate" "default-fonts"
## [4] "default" "duke-blue" "fc-fonts"
## [7] "fc" "hygge-duke" "hygge"
## [10] "kunoichi" "lucy-fonts" "lucy"
## [13] "metropolis-fonts" "metropolis" "middlebury-fonts"
## [16] "middlebury" "ninjutsu" "rladies-fonts"
## [19] "rladies" "robot-fonts" "robot"
## [22] "rutgers-fonts" "rutgers" "shinobi"
## [25] "tamu-fonts" "tamu" "uo-fonts"
## [28] "uo" "uol-fonts" "uol"

These go to your YAML

output:
xaringan::moon_reader:
css: [default, rladies, rladies-fonts]
10 / 39

Somewhere in the middle?

Add my-style.css to the YAML with the current css file

output:
xaringan::moon_reader:
css: [default, rladies, lucy-fonts, my-style.css]
12 / 39

Somewhere in the middle?

Add my-style.css to the YAML with the current css file

output:
xaringan::moon_reader:
css: [default, rladies, lucy-fonts, my-style.css]

While sitting in my-style.css file,

.red { color: red; }
.remark-code-line-highlighted { background-color: #e8c9e9; }
.remark-code, .remark-inline-code {
color: #7c347f;
font-weight: 300;
}
12 / 39

Somewhere in the middle?

Add my-style.css to the YAML with the current css file

output:
xaringan::moon_reader:
css: [default, rladies, lucy-fonts, my-style.css]

While sitting in my-style.css file,

.red { color: red; }
.remark-code-line-highlighted { background-color: #e8c9e9; }
.remark-code, .remark-inline-code {
color: #7c347f;
font-weight: 300;
}

I've changed it to red.

12 / 39

Where to find the themes files?

You can find CSS files here. However, don't save your own CSS file here.

13 / 39

Where to find the themes files?

You can find CSS files here. However, don't save your own CSS file here.

- start with an existing theme

- try change something and see what happens

13 / 39

Meet slidex

It converts PowerPoint slides to xaringan slides

14 / 39

Start with the YAML

Simple version

---
title: "How to Make Slides in R"
output:
xaringan::moon_reader
---
15 / 39

Start with the YAML

Simple version

---
title: "How to Make Slides in R"
output:
xaringan::moon_reader
---

More options

---
title: "How to Make Slides in R"
subtitle: "Using xaringan"
author: "Zhi Yang"
date: "2019/2/26"
output:
xaringan::moon_reader:
css: ["default", "rladies",
"lucy-fonts",
"my-style.css"]
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
#chakra: "remark.js"
---
15 / 39

Make new slides

Three dashes --- gives a new slide

---
title: "How to Make Slides in R"
output:
xaringan::moon_reader
---
A slide
---
Another slide
16 / 39

Align an entire slide

Horizontal

left,
center,
right

Vertical

top,
middle,
bottom
---
class: center, middle
# Demo slide
This is a center- and middle- aligned slide.
17 / 39

Align the text

Horizontal

.left[texts]
.center[texts]
.right[texts]
---
class: center, middle
# Demo slide
.right[This is a center- and middle- aligned slide.]
18 / 39

Demo slide

This is a center- and middle- aligned slide.

19 / 39

Incremental reveals

# Hi
Did you know
--
you can
--
do this?

Hi

20 / 39

Incremental reveals

# Hi
Did you know
--
you can
--
do this?

Hi

Did you know

20 / 39

Incremental reveals

# Hi
Did you know
--
you can
--
do this?

Hi

Did you know

you can

20 / 39

Incremental reveals

# Hi
Did you know
--
you can
--
do this?

Hi

Did you know

you can

do this?

20 / 39

Code and higtlight

use the trailing comment #<< to highlight specific lines of the code

Source:

```{r}
namedata <- babynames %>%
filter(name == "Orange") %>%
filter(sex == "M") %>% #<<
arrange(year)
head(namedata)
```

Output:

namedata <- babynames %>%
filter(name == "Orange") %>%
filter(sex == "M") %>%
arrange(year)
head(namedata)
21 / 39

Output and higtlight

use the chunk option highlight.output to highlight specific lines of the text output

Source:

```{r head, highlight.output=c(1, 3)}
namedata <- babynames %>%
filter(name == "Orange") %>%
filter(sex == "M") %>% #<<
arrange(year)
head(namedata)
```

Output:

## # A tibble: 6 x 5
## year sex name n prop
## <dbl> <chr> <chr> <int> <dbl>
## 1 1881 M Orange 9 0.0000831
## 2 1882 M Orange 8 0.0000656
## 3 1883 M Orange 11 0.0000978
## 4 1884 M Orange 13 0.000106
## 5 1885 M Orange 8 0.000069
## 6 1886 M Orange 7 0.0000588
22 / 39

Two-columns

.pull-left[
```{r refname echo=TRUE, eval=FALSE}
your R code
```
]
.pull-right[
```{r ref.label="refname" echo=FALSE, eval=TRUE}
```
]

.pull-left and .pull-right provide 47% width

23 / 39

Two-columns

.pull-left[
```{r refname echo=TRUE, eval=FALSE}
your R code
```
]
.pull-right[
```{r ref.label="refname" echo=FALSE, eval=TRUE}
```
]

.pull-left and .pull-right provide 47% width

namedata <- babynames %>%
filter(name == "Orange") %>%
filter(sex == "M") %>%
arrange(year)
head(namedata)
23 / 39

Two-columns

.pull-left[
```{r refname echo=TRUE, eval=FALSE}
your R code
```
]
.pull-right[
```{r ref.label="refname" echo=FALSE, eval=TRUE}
```
]

.pull-left and .pull-right provide 47% width

namedata <- babynames %>%
filter(name == "Orange") %>%
filter(sex == "M") %>%
arrange(year)
head(namedata)
## # A tibble: 6 x 5
## year sex name n prop
## <dbl> <chr> <chr> <int> <dbl>
## 1 1881 M Orange 9 0.0000831
## 2 1882 M Orange 8 0.0000656
## 3 1883 M Orange 11 0.0000978
## 4 1884 M Orange 13 0.000106
## 5 1885 M Orange 8 0.000069
## 6 1886 M Orange 7 0.0000588
23 / 39

Two-columns

.left-column[
```{r evel = FALSE}
Your R code
```
]
.right-column[
```{r evel = FALSE, echo = FALSE}
Your R code
```
]

.left-column and .right-column provide 20% and 75% width

24 / 39

Two-columns

.left-column[
```{r evel = FALSE}
Your R code
```
]
.right-column[
```{r evel = FALSE, echo = FALSE}
Your R code
```
]

.left-column and .right-column provide 20% and 75% width

head(gss_cat)
24 / 39

Two-columns

.left-column[
```{r evel = FALSE}
Your R code
```
]
.right-column[
```{r evel = FALSE, echo = FALSE}
Your R code
```
]

.left-column and .right-column provide 20% and 75% width

head(gss_cat)
## # A tibble: 6 x 9
## year marital age race rincome partyid relig denom tvhours
## <int> <fct> <int> <fct> <fct> <fct> <fct> <fct> <int>
## 1 2000 Never ma~ 26 White $8000 to~ Ind,near ~ Protest~ Southe~ 12
## 2 2000 Divorced 48 White $8000 to~ Not str r~ Protest~ Baptis~ NA
## 3 2000 Widowed 67 White Not appl~ Independe~ Protest~ No den~ 2
## 4 2000 Never ma~ 39 White Not appl~ Ind,near ~ Orthodo~ Not ap~ 4
## 5 2000 Divorced 25 White Not appl~ Not str d~ None Not ap~ 1
## 6 2000 Married 25 White $20000 -~ Strong de~ Protest~ Southe~ NA
24 / 39

Add a table

head(iris, n = 3)
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
knitr::kable(head(iris, n = 3), 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

Set the table to be the HTML format

25 / 39

Add a plot

par(mar = c(4, 4, 1, 0.1))
plot(cars, pch = 19, col = "darkgray", las = 1)

use fig.height and fig.width to control the size

26 / 39

Add an image

![](/imgs/ocrug.jpeg)

27 / 39

Resize it

Should it be something like ![](/imgs/ocrug.jpeg){width=10px} ? 😢

28 / 39

Resize it

Should it be something like ![](/imgs/ocrug.jpeg){width=10px} ? 😢

Option 1:

<img src="imgs/ocrug.jpeg" width="20%" />

28 / 39

Resize it

Should it be something like ![](/imgs/ocrug.jpeg){width=10px} ? 😢

Option 1:

<img src="imgs/ocrug.jpeg" width="20%" />

Option 2:

```{r out.width = "20%", eval=TRUE}
knitr::include_graphics("imgs/ocrug.jpeg")
```

28 / 39

Full screen

background-image: url(/imgs/ocrug.jpeg)
background-size: cover
29 / 39

Rescale only

background-image: url(/imgs/ocrug.jpeg)
background-size: contain
30 / 39

Change position

background-image: url(/imgs/ocrug.jpeg)
background-size: contain
background-position: bottom
31 / 39

Use online image

background-image: url(https://secure.meetupstatic.com/photos/event/2/b/9/e/600_471491166.jpeg)
background-size: contain
background-position: bottom
32 / 39

Logos

background-image: url(imgs/ocrug_logo.png), url(imgs/ocrug_logo.png)
background-position: 0% 100%, 100% 0%
background-size: 30%, 10%
33 / 39

Hosting slides

34 / 39

Netlify 💻

Step 1: go to netlify.com

Step 2: connect with your Github account

35 / 39

Netlify 💻

Step 3: select a repo

36 / 39

Netlify 💻

Step 3: select a repo

Step 4: select a branch

36 / 39

Netlify 💻

Step 5: deploy a site

Step 6: change site name

37 / 39

More info...

38 / 39

Thanks!


@zhiiiyang

https://github.com/zhiiiyang/XaringanTutorial

Slides created via the R package xaringan

Template created by Alison Hill

39 / 39

How I met xaringan Sharingan

An R user who would like to share awesome things in R

2 / 39
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