+ - 0:00:00
Notes for current slide
Notes for next slide
These slides are viewed best by Chrome and occasionally need to be refreshed if elements did not load properly. See here for PDF .


Press the right arrow to progress to the next slide!

1/20

Beyond Beamer

Modern and Dynamic Presentations with
R Markdown

Emi Tanaka

Department of Econometrics and Business Statistics

emi.tanaka@monash.edu @statsgen

30th Jun 2020 @ SSA NSW/Canberra x R-Ladies Sydney/Canberra | via Zoom

1/20

Link to all the materials

2/20


This talk is NOT about:


how to present well or communicate

3/20


This talk is NOT about:


how to present well or communicate


how to design your slides

3/20

🎯


Learn about Beamer R Markdown

4/20

🎯


Learn about Beamer R Markdown


Why care about R Markdown?

4/20

🎯


Learn about Beamer R Markdown


Why care about R Markdown?


Get started with xaringan = R Markdown remark.js HTML/CSS/JS

4/20

🎯


Learn about Beamer R Markdown


Why care about R Markdown?


Get started with xaringan = R Markdown remark.js HTML/CSS/JS


Why HTML slides?

4/20

🎯


Learn about Beamer R Markdown


Why care about R Markdown?


Get started with xaringan = R Markdown remark.js HTML/CSS/JS


Why HTML slides?


Questions? Do ask away! 👩🏻‍💻

4/20
For the beamer users who are yet to use
R Markdown
5/20

Beamer LaTeX document class

example-beamer-clean.tex

\documentclass[10pt,aspectratio=169]{beamer}
\usepackage{amssymb,amsmath}
\usepackage{lmodern}
\usepackage{hyperref, url}
\usetheme{Copenhagen}
\usecolortheme{dolphin}
\usefonttheme{structurebold}
\title{This is a Beamer presentation made using \LaTeX}
\subtitle{}
\author{Emi Tanaka}
\date{30th June 2020}
\institute{Monash University}
\begin{document}
\frame{\titlepage}
\begin{frame}
\tableofcontents[hideallsubsections]
\end{frame}
\section{Basics}
\begin{frame}{Setting up the YAML}
\begin{block}{R Markdown YAML}
\texttt{output:\ beamer\_presentation}
\end{block}
Also check out the
\href{https://github.com/eddelbuettel/binb}{\texttt{binb} R-package}.
\end{frame}
\section{Clean syntax}
\begin{frame}{Example: Writing mathematics is as usual}
Consider a general linear mixed models:
$\boldsymbol{y} = \mathbf{X}\boldsymbol{\beta} + \mathbf{Z}\boldsymbol{u} + \boldsymbol{e}$
where
\begin{itemize}
\item
$\boldsymbol{y}$ is a $n\times 1$ vector of observations,
\item
$\mathbf{X}$ is a $n\times p$ design matrix for fixed effects
$\boldsymbol{\beta}$,
\item
$\mathbf{Z}$ is a $n\times q$ design matrix for fixed effects
$\boldsymbol{u}$, and
\item
$\boldsymbol{e}$ is a $n\times 1$ vector of random error.
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Simplified content writing: itemized list}
\begin{columns}[T]
\begin{column}{0.48\textwidth}
\begin{block}{Plain \LaTeX}
\small
\begin{verbatim}
\begin{itemize}
\item
$\boldsymbol{y}$ is a
$n\times 1$ vector of
observations,
\item
$\mathbf{X}$ is a $n\times p$
design matrix for fixed effects
$\boldsymbol{\beta}$$,
\item
$\mathbf{Z}$ is a $n\times q$
design matrix for fixed effects
$\boldsymbol{u}$, and
\item
$\boldsymbol{e}$ is a $n\times 1$
vector of random error.
\end{itemize}
\end{verbatim}
\end{block}
\end{column}
\begin{column}{0.48\textwidth}
\begin{block}{Markdown syntax}
\small
\vspace{0.5cm}
\begin{verbatim}
* $\boldsymbol{y}$ is a $n\times 1$
vector of observations,
* $\mathbf{X}$ is a $n\times p$
design matrix for fixed effects
$\boldsymbol{\beta}$,
* $\mathbf{Z}$ is a $n\times q$
design matrix for fixed effects
$\boldsymbol{u}$, and
* $\boldsymbol{e}$ is a $n\times 1$
vector of random error.
\end{verbatim}
\end{block}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]{Make new frame}
\begin{columns}[T]
\begin{column}{0.48\textwidth}
Instead of
\begin{block}{\LaTeX}
\begin{verbatim}
\begin{frame}{Title}
Content
\ end{frame}
\end{verbatim}
\end{block}
do
\begin{block}{markdown}
\begin{verbatim}
## Title
Content
\end{verbatim}
\end{block}
\end{column}
\begin{column}{0.48\textwidth}
In the \textbf{R Markdown YAML} set:
\begin{verbatim}
output:
beamer_presentation:
slide_level: 2
\end{verbatim}
\begin{itemize}
\item
then a heading at slide level starts a new frame; or
\item
a horizontal line, like \texttt{-\/-\/-}, starts a new frame.
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]{Multi-column output}
Stick with \LaTeX or Pandoc syntax (both will work)
\begin{columns}[T]
\begin{column}{0.48\textwidth}
\begin{block}{Plain \LaTeX}
\begin{verbatim}
\begin{columns}
\begin{column}{0.5\textwidth}
Column 1 content
\end{column}
\begin{column}{0.5\textwidth}
Column 2 content
\end{column}
\end{columns}
\end{verbatim}
\end{block}
\end{column}
\begin{column}{0.48\textwidth}
\begin{block}{Pandoc syntax}
\begin{verbatim}
:::: columns
::: column
Column 1 content
:::
::: column
Column 2 content
:::
::::
\end{verbatim}
\end{block}
\end{column}
\end{columns}
\end{frame}
\section{Appearance}
\begin{frame}[fragile]{Pandoc options}
\begin{itemize}
\item
See
\href{https://pandoc.org/MANUAL.html\#variables-for-beamer-slides}{Pandoc
manual} for all the variables available to modify in the YAML.
\begin{itemize}
\item
E.g. \texttt{aspectratio:\ 43} for 4:3 ratio.
\end{itemize}
\item
See also
\href{https://pandoc.org/MANUAL.html\#producing-slide-shows-with-pandoc}{Producing
slide shows with pandoc}
\begin{itemize}
\item
E.g. Speaker notes
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile,shrink]{Beamer frame atributes}
\begin{verbatim}
## Beamer frame atributes {.shrink}
\end{verbatim}
\begin{itemize}
\item
The frame attributes in Section 8.1 of the
\href{http://mirror.aarnet.edu.au/pub/CTAN/macros/latex/contrib/beamer/doc/beameruserguide.pdf}{Beamer
User's Guide} can be used if inserted after header level as
\texttt{\{.attribute\}} where \texttt{attribute} replaced with
\begin{itemize}
\item
\texttt{allowdisplaybreaks}
\item
\texttt{allowframebreaks}
\item
\texttt{b}
\item
\texttt{c}
\item
\texttt{t}
\item
\texttt{environment}
\item
\texttt{label}
\item
\texttt{plain}
\item
\texttt{shrink}
\item
\texttt{standout}
\item
\texttt{noframenumbering}
\end{itemize}
\end{itemize}
\end{frame}
\section{Animation}
\begin{frame}[fragile]{Animation}
\begin{itemize}[<+->]
\item
First step
\item
Second step
\item
Third step
\end{itemize}
\pause
You can also include pauses with \texttt{.\ .\ .}
\end{frame}
\end{document}

example-beamer-clean.pdf


6/20

Clean syntax with Markdown

example-beamer-clean.tex

\documentclass[10pt,aspectratio=169]{beamer}
\usepackage{amssymb,amsmath}
\usepackage{lmodern}
\usepackage{hyperref, url}
\usetheme{Copenhagen}
\usecolortheme{dolphin}
\usefonttheme{structurebold}
\title{This is a Beamer presentation made using \LaTeX}
\subtitle{}
\author{Emi Tanaka}
\date{30th June 2020}
\institute{Monash University}
\begin{document}
\frame{\titlepage}
\begin{frame}
\tableofcontents[hideallsubsections]
\end{frame}
\section{Basics}
\begin{frame}{Setting up the YAML}
\begin{block}{R Markdown YAML}
\texttt{output:\ beamer\_presentation}
\end{block}
Also check out the
\href{https://github.com/eddelbuettel/binb}{\texttt{binb} R-package}.
\end{frame}
\section{Clean syntax}
\begin{frame}{Example: Writing mathematics is as usual}
Consider a general linear mixed models:
$\boldsymbol{y} = \mathbf{X}\boldsymbol{\beta} + \mathbf{Z}\boldsymbol{u} + \boldsymbol{e}$
where
\begin{itemize}
\item
$\boldsymbol{y}$ is a $n\times 1$ vector of observations,
\item
$\mathbf{X}$ is a $n\times p$ design matrix for fixed effects
$\boldsymbol{\beta}$,
\item
$\mathbf{Z}$ is a $n\times q$ design matrix for fixed effects
$\boldsymbol{u}$, and
\item
$\boldsymbol{e}$ is a $n\times 1$ vector of random error.
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Simplified content writing: itemized list}
\begin{columns}[T]
\begin{column}{0.48\textwidth}
\begin{block}{Plain \LaTeX}
\small
\begin{verbatim}
\begin{itemize}
\item
$\boldsymbol{y}$ is a
$n\times 1$ vector of
observations,
\item
$\mathbf{X}$ is a $n\times p$
design matrix for fixed effects
$\boldsymbol{\beta}$$,
\item
$\mathbf{Z}$ is a $n\times q$
design matrix for fixed effects
$\boldsymbol{u}$, and
\item
$\boldsymbol{e}$ is a $n\times 1$
vector of random error.
\end{itemize}
\end{verbatim}
\end{block}
\end{column}
\begin{column}{0.48\textwidth}
\begin{block}{Markdown syntax}
\small
\vspace{0.5cm}
\begin{verbatim}
* $\boldsymbol{y}$ is a $n\times 1$
vector of observations,
* $\mathbf{X}$ is a $n\times p$
design matrix for fixed effects
$\boldsymbol{\beta}$,
* $\mathbf{Z}$ is a $n\times q$
design matrix for fixed effects
$\boldsymbol{u}$, and
* $\boldsymbol{e}$ is a $n\times 1$
vector of random error.
\end{verbatim}
\end{block}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]{Make new frame}
\begin{columns}[T]
\begin{column}{0.48\textwidth}
Instead of
\begin{block}{\LaTeX}
\begin{verbatim}
\begin{frame}{Title}
Content
\ end{frame}
\end{verbatim}
\end{block}
do
\begin{block}{markdown}
\begin{verbatim}
## Title
Content
\end{verbatim}
\end{block}
\end{column}
\begin{column}{0.48\textwidth}
In the \textbf{R Markdown YAML} set:
\begin{verbatim}
output:
beamer_presentation:
slide_level: 2
\end{verbatim}
\begin{itemize}
\item
then a heading at slide level starts a new frame; or
\item
a horizontal line, like \texttt{-\/-\/-}, starts a new frame.
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]{Multi-column output}
Stick with \LaTeX or Pandoc syntax (both will work)
\begin{columns}[T]
\begin{column}{0.48\textwidth}
\begin{block}{Plain \LaTeX}
\begin{verbatim}
\begin{columns}
\begin{column}{0.5\textwidth}
Column 1 content
\end{column}
\begin{column}{0.5\textwidth}
Column 2 content
\end{column}
\end{columns}
\end{verbatim}
\end{block}
\end{column}
\begin{column}{0.48\textwidth}
\begin{block}{Pandoc syntax}
\begin{verbatim}
:::: columns
::: column
Column 1 content
:::
::: column
Column 2 content
:::
::::
\end{verbatim}
\end{block}
\end{column}
\end{columns}
\end{frame}
\section{Appearance}
\begin{frame}[fragile]{Pandoc options}
\begin{itemize}
\item
See
\href{https://pandoc.org/MANUAL.html\#variables-for-beamer-slides}{Pandoc
manual} for all the variables available to modify in the YAML.
\begin{itemize}
\item
E.g. \texttt{aspectratio:\ 43} for 4:3 ratio.
\end{itemize}
\item
See also
\href{https://pandoc.org/MANUAL.html\#producing-slide-shows-with-pandoc}{Producing
slide shows with pandoc}
\begin{itemize}
\item
E.g. Speaker notes
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile,shrink]{Beamer frame atributes}
\begin{verbatim}
## Beamer frame atributes {.shrink}
\end{verbatim}
\begin{itemize}
\item
The frame attributes in Section 8.1 of the
\href{http://mirror.aarnet.edu.au/pub/CTAN/macros/latex/contrib/beamer/doc/beameruserguide.pdf}{Beamer
User's Guide} can be used if inserted after header level as
\texttt{\{.attribute\}} where \texttt{attribute} replaced with
\begin{itemize}
\item
\texttt{allowdisplaybreaks}
\item
\texttt{allowframebreaks}
\item
\texttt{b}
\item
\texttt{c}
\item
\texttt{t}
\item
\texttt{environment}
\item
\texttt{label}
\item
\texttt{plain}
\item
\texttt{shrink}
\item
\texttt{standout}
\item
\texttt{noframenumbering}
\end{itemize}
\end{itemize}
\end{frame}
\section{Animation}
\begin{frame}[fragile]{Animation}
\begin{itemize}[<+->]
\item
First step
\item
Second step
\item
Third step
\end{itemize}
\pause
You can also include pauses with \texttt{.\ .\ .}
\end{frame}
\end{document}

example-beamer.Rmd

---
title: This is a Beamer presentation made using R Markdown
subtitle: "`rmarkdown::beamer_presentation`"
author: Emi Tanaka
institute: Monash University
date: "30th June 2020"
fontsize: 10pt
mathspec: true # for metropolis theme
aspectratio: 169 # 16:9
#classoption: handout
output:
beamer_presentation:
theme: "Copenhagen"
# https://deic-web.uab.cat/~iblanes/beamer_gallery/index_by_theme.html
#theme: "metropolis" # special
colortheme: "dolphin"
# https://deic-web.uab.cat/~iblanes/beamer_gallery/index_by_color.html
fonttheme: "structurebold"
# https://deic-web.uab.cat/~iblanes/beamer_gallery/index_by_font.html
latex_engine: xelatex # for metropolis theme
toc: true
slide_level: 2
keep_tex: true
#includes:
# in_header: preamble.tex
header-includes:
- \usepackage{fancyvrb}
---
# Basics
## Setting up the YAML
::: block
### R Markdown YAML
`output: beamer_presentation`
:::
Also check out the [`binb` R-package](https://github.com/eddelbuettel/binb).
# Clean syntax
## Example: Writing mathematics is as usual
Consider a general linear mixed models:
$$\boldsymbol{y} = \mathbf{X}\boldsymbol{\beta} + \mathbf{Z}\boldsymbol{u} + \boldsymbol{e}$$
where
* $\boldsymbol{y}$ is a $n\times 1$ vector of observations,
* $\mathbf{X}$ is a $n\times p$ design matrix for fixed effects $\boldsymbol{\beta}$,
* $\mathbf{Z}$ is a $n\times q$ design matrix for fixed effects $\boldsymbol{u}$, and
* $\boldsymbol{e}$ is a $n\times 1$ vector of random error.
## Simplified content writing: itemized list
:::::: columns
::: column
### Plain \LaTeX
\small
```
\begin{itemize}
\item
$\boldsymbol{y}$ is a
$n\times 1$ vector of
observations,
\item
$\mathbf{X}$ is a $n\times p$
design matrix for fixed effects
$\boldsymbol{\beta}$$,
\item
$\mathbf{Z}$ is a $n\times q$
design matrix for fixed effects
$\boldsymbol{u}$, and
\item
$\boldsymbol{e}$ is a $n\times 1$
vector of random error.
\end{itemize}
```
:::
::: column
### Markdown syntax
\small
\vspace{0.5cm}
```
* $\boldsymbol{y}$ is a $n\times 1$
vector of observations,
* $\mathbf{X}$ is a $n\times p$
design matrix for fixed effects
$\boldsymbol{\beta}$,
* $\mathbf{Z}$ is a $n\times q$
design matrix for fixed effects
$\boldsymbol{u}$, and
* $\boldsymbol{e}$ is a $n\times 1$
vector of random error.
```
:::
::::::
## Make new frame {.fragile}
::: columns
::: column
Instead of
::: block
### \LaTeX
```
\begin{frame}{Title}
Content
\ end{frame}
```
:::
do
### markdown
```
## Title
Content
```
:::
::: column
In the **R Markdown YAML** set:
```
output:
beamer_presentation:
slide_level: 2
```
* then a heading at slide level starts a new frame; or
* a horizontal line, like `---`, starts a new frame.
:::
:::
## Multi-column output
Stick with \LaTeX or Pandoc syntax (both will work)
:::: columns
::: column
### Plain \LaTeX
```
\begin{columns}
\begin{column}{0.5\textwidth}
Column 1 content
\end{column}
\begin{column}{0.5\textwidth}
Column 2 content
\end{column}
\end{columns}
```
:::
::: column
### Pandoc syntax
```
:::: columns
::: column
Column 1 content
:::
::: column
Column 2 content
:::
::::
```
:::
::::
# Appearance
## Pandoc options
* See [Pandoc manual](https://pandoc.org/MANUAL.html#variables-for-beamer-slides) for all the variables available to modify in the YAML.
* E.g. `aspectratio: 43` for 4:3 ratio.
* See also [Producing slide shows with pandoc](https://pandoc.org/MANUAL.html#producing-slide-shows-with-pandoc)
* E.g. Speaker notes
## Beamer frame atributes {.shrink}
```
## Beamer frame atributes {.shrink}
```
* The frame attributes in Section 8.1 of the [Beamer User's Guide](http://mirror.aarnet.edu.au/pub/CTAN/macros/latex/contrib/beamer/doc/beameruserguide.pdf) can be used if inserted after header level as `{.attribute}` where `attribute` replaced with
* `allowdisplaybreaks`
* `allowframebreaks`
* `b`
* `c`
* `t`
* `environment`
* `label`
* `plain`
* `shrink`
* `standout`
* `noframenumbering`
# Animation
::: incremental
* First step
* Second step
* Third step
:::
. . .
You can also include pauses with `. . . `
```{r export, include = FALSE}
library(pdftools)
pdf_convert("example-beamer.pdf", format = "png", dpi = 200)
fns <- list.files(pattern = "example-beamer_")
purrr::walk(fns, ~{
file.copy(.x, paste0("images/", .x), overwrite = TRUE)
file.remove(.x)
})
```
7/20

Beamer LaTeX with R Markdown

example-beamer.Rmd

---
title: This is a Beamer presentation made using R Markdown
subtitle: "`rmarkdown::beamer_presentation`"
author: Emi Tanaka
institute: Monash University
date: "30th June 2020"
fontsize: 10pt
mathspec: true # for metropolis theme
aspectratio: 169 # 16:9
#classoption: handout
output:
beamer_presentation:
theme: "Copenhagen"
# https://deic-web.uab.cat/~iblanes/beamer_gallery/index_by_theme.html
#theme: "metropolis" # special
colortheme: "dolphin"
# https://deic-web.uab.cat/~iblanes/beamer_gallery/index_by_color.html
fonttheme: "structurebold"
# https://deic-web.uab.cat/~iblanes/beamer_gallery/index_by_font.html
latex_engine: xelatex # for metropolis theme
toc: true
slide_level: 2
keep_tex: true
#includes:
# in_header: preamble.tex
header-includes:
- \usepackage{fancyvrb}
---
# Basics
## Setting up the YAML
::: block
### R Markdown YAML
`output: beamer_presentation`
:::
Also check out the [`binb` R-package](https://github.com/eddelbuettel/binb).
# Clean syntax
## Example: Writing mathematics is as usual
Consider a general linear mixed models:
$$\boldsymbol{y} = \mathbf{X}\boldsymbol{\beta} + \mathbf{Z}\boldsymbol{u} + \boldsymbol{e}$$
where
* $\boldsymbol{y}$ is a $n\times 1$ vector of observations,
* $\mathbf{X}$ is a $n\times p$ design matrix for fixed effects $\boldsymbol{\beta}$,
* $\mathbf{Z}$ is a $n\times q$ design matrix for fixed effects $\boldsymbol{u}$, and
* $\boldsymbol{e}$ is a $n\times 1$ vector of random error.
## Simplified content writing: itemized list
:::::: columns
::: column
### Plain \LaTeX
\small
```
\begin{itemize}
\item
$\boldsymbol{y}$ is a
$n\times 1$ vector of
observations,
\item
$\mathbf{X}$ is a $n\times p$
design matrix for fixed effects
$\boldsymbol{\beta}$$,
\item
$\mathbf{Z}$ is a $n\times q$
design matrix for fixed effects
$\boldsymbol{u}$, and
\item
$\boldsymbol{e}$ is a $n\times 1$
vector of random error.
\end{itemize}
```
:::
::: column
### Markdown syntax
\small
\vspace{0.5cm}
```
* $\boldsymbol{y}$ is a $n\times 1$
vector of observations,
* $\mathbf{X}$ is a $n\times p$
design matrix for fixed effects
$\boldsymbol{\beta}$,
* $\mathbf{Z}$ is a $n\times q$
design matrix for fixed effects
$\boldsymbol{u}$, and
* $\boldsymbol{e}$ is a $n\times 1$
vector of random error.
```
:::
::::::
## Make new frame {.fragile}
::: columns
::: column
Instead of
::: block
### \LaTeX
```
\begin{frame}{Title}
Content
\ end{frame}
```
:::
do
### markdown
```
## Title
Content
```
:::
::: column
In the **R Markdown YAML** set:
```
output:
beamer_presentation:
slide_level: 2
```
* then a heading at slide level starts a new frame; or
* a horizontal line, like `---`, starts a new frame.
:::
:::
## Multi-column output
Stick with \LaTeX or Pandoc syntax (both will work)
:::: columns
::: column
### Plain \LaTeX
```
\begin{columns}
\begin{column}{0.5\textwidth}
Column 1 content
\end{column}
\begin{column}{0.5\textwidth}
Column 2 content
\end{column}
\end{columns}
```
:::
::: column
### Pandoc syntax
```
:::: columns
::: column
Column 1 content
:::
::: column
Column 2 content
:::
::::
```
:::
::::
# Appearance
## Pandoc options
* See [Pandoc manual](https://pandoc.org/MANUAL.html#variables-for-beamer-slides) for all the variables available to modify in the YAML.
* E.g. `aspectratio: 43` for 4:3 ratio.
* See also [Producing slide shows with pandoc](https://pandoc.org/MANUAL.html#producing-slide-shows-with-pandoc)
* E.g. Speaker notes
## Beamer frame atributes {.shrink}
```
## Beamer frame atributes {.shrink}
```
* The frame attributes in Section 8.1 of the [Beamer User's Guide](http://mirror.aarnet.edu.au/pub/CTAN/macros/latex/contrib/beamer/doc/beameruserguide.pdf) can be used if inserted after header level as `{.attribute}` where `attribute` replaced with
* `allowdisplaybreaks`
* `allowframebreaks`
* `b`
* `c`
* `t`
* `environment`
* `label`
* `plain`
* `shrink`
* `standout`
* `noframenumbering`
# Animation
::: incremental
* First step
* Second step
* Third step
:::
. . .
You can also include pauses with `. . . `
```{r export, include = FALSE}
library(pdftools)
pdf_convert("example-beamer.pdf", format = "png", dpi = 200)
fns <- list.files(pattern = "example-beamer_")
purrr::walk(fns, ~{
file.copy(.x, paste0("images/", .x), overwrite = TRUE)
file.remove(.x)
})
```

example-beamer.pdf


8/20

Why care about R Markdown?

Clean syntax for writing content

Integrates code and output easily:

  • great for tutorials, workshops, lectures to demonstrate how to use code
  • great for presenting analytical results

Some code syntax highlighting code done for you


Verbatim code

mtcars %>%
mutate(new = 30, string = "hello")

Syntax highlighting

mtcars %>%
mutate(new = 30, string = "hello")

(achieved commonly using listings package in LaTeX)

9/20

R Markdown Beamer

example-beamer2.Rmd

---
title: The Power of R Markdown
subtitle: "`rmarkdown::beamer_presentation`"
author: Emi Tanaka
institute: Monash University
date: "30th June 2020"
fontsize: 10pt
mathspec: true # for metropolis theme
aspectratio: 169 # 16:9
#classoption: handout
output:
beamer_presentation:
theme: "Madrid"
# https://deic-web.uab.cat/~iblanes/beamer_gallery/index_by_theme.html
#theme: "metropolis" # special
colortheme: "whale"
# https://deic-web.uab.cat/~iblanes/beamer_gallery/index_by_color.html
fonttheme: "professionalfonts"
# https://deic-web.uab.cat/~iblanes/beamer_gallery/index_by_font.html
latex_engine: xelatex # for metropolis theme
toc: false
slide_level: 2
keep_tex: true
#includes:
# in_header: preamble.tex
header-includes:
- \usepackage{fancyvrb}
- \usepackage{graphicx}
---
# Power of R Markdown
## Example: my fancy graph
Behold! My plot that shows the linear trend!
```{r myplot, echo = FALSE, message = FALSE, fig.align = "center", fig.height = 2, fig.width = 4}
library(tidyverse)
ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) +
geom_point() + theme_bw(base_size = 18)
```
## Example: code and output demonstration
This is how you use `tidyverse` to fit simple linear models to each level in `cyl` .
```{r pkgshow, message = FALSE}
library(tidyverse)
mtcars %>%
split(.$cyl) %>%
map_dfr(~{
fit <- lm(mpg ~ disp, data = .)
slope_ests <- coef(fit)
c(cyl = .$cyl[1], n = nrow(.), slope_ests)
})
```
## R Markdown Motivation: More robust to modifications
```{r, echo = FALSE, out.width = "100%"}
knitr::include_graphics("images/rmd-motivation.png")
```
```{r export, include = FALSE}
library(pdftools)
pdf_convert("example-beamer2.pdf", format = "png", dpi = 200)
fns <- list.files(pattern = "example-beamer2_")
purrr::walk(fns, ~{
file.copy(.x, paste0("images/", .x), overwrite = TRUE)
file.remove(.x)
})
```

example-beamer2.pdf


10/20
For those that want to learn about `xaringan`
11/20

Getting started with xaringan

12/20

Check out Earo Wang's talk at R-Ladies Auckland

Slide + Code here.

13/20

Also Alison Hill's slides!

14/20

Getting started with xaringan slides

install.packages("xaringan")

RStudio > File > New File > R Markdown > From Template > Ninja Presentation


  • You do have to know HTML/CSS
  • JS helps as well
15/20

Getting started with xaringan slides

install.packages("xaringan")

RStudio > File > New File > R Markdown > From Template > Ninja Presentation


  • You do have to know HTML/CSS
  • JS helps as well
  • But if you don't know then
install.packages("xaringanthemer")

RStudio > File > New File > R Markdown > From Template > Ninja Themed Presentation

15/20

Why HTML slides?

Interactivity! Animate!

DT::datatable(mtcars)
16/20

Interactive plots into html slides

library(plotly) # for interactive plots
g <- ggplot(mtcars) +
aes(mpg, disp, color = factor(cyl)) +
geom_point() +
theme_bw(base_size = 20)
p <- ggplotly(g)
htmltools::save_html(p, file = "example-plotly.html")

Doable, but slightly fiddly to embed in slides (see Di Cook's blog).

<iframe src="example-plotly.html" width="550" height="500"></iframe>
17/20

Side-by-side code and output demo

---
title: "ggplot tutorial"
subtitle: "with kunoichi + ninjutsu theme"
author: "<br><br> Emi Tanaka"
date: "<br>2018/09/16"
output:
xaringan::moon_reader:
lib_dir: libs2
css: ["kunoichi", "ninjutsu"]
nature:
ratio: "16:9"
highlightLines: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE)
knitr::opts_chunk$set(fig.height=6, out.width="100%")
library(ggplot2)
# reveal lines up to `upto` and highlight lines `highlight`
reveal <- function(name, upto, highlight = upto) {
content <- knitr:::knit_code$get(name)
content[upto] <- gsub("+", "", content[upto], fixed=T)
content[highlight] <- paste(content[highlight], "#<<")
content[1:upto]
}
partial_knit_chunks <- function(chunk_name) {
# Create slide for lines 1:N for each line N in the given chunk
idx_lines <- seq_along(knitr:::knit_code$get(chunk_name))
partial_knit_steps <- glue::glue(
"class: split-40",
"count: false",
"",
".column[.content[",
"```{r plot{{idx_lines}}, eval=FALSE, code=reveal('{{chunk_name}}', {{idx_lines}})}",
"```",
"]]",
".column[.content.center[",
"```{r output{{idx_lines}}, echo=FALSE, code=reveal('{{chunk_name}}', {{idx_lines}})}",
"```",
"]]",
.open = "{{", .close = "}}", .sep = "\n"
)
glue::glue_collapse(partial_knit_steps, "\n---\n")
}
```
```{r complete, eval=F, echo=F}
ggplot(iris) +
aes(Sepal.Length, Sepal.Width) +
geom_point() +
labs(x = "Sepal Length") +
labs(y = "Sepal Width") +
labs(title="The famous iris data") +
labs(subtitle="Data collected by Anderson, Edgar (1935)") +
aes(color= Species) +
theme_bw(base_size=16)
```
`r paste(knitr::knit(text = partial_knit_chunks("complete")), collapse = "\n")`
<!-- This css chunk can't be before the first class: split-40... lines -->
```{css, eval=TRUE}
.remark-code{ line-height: 2; }
```
18/20

Bibiliography and citations

See here for using bibtex citation in xaringan slides.


References

[1] H. Wickham, M. Averick, J. Bryan, et al. "Welcome to the tidyverse". In: Journal of Open Source Software 4.43 (2019), p. 1686. DOI: 10.21105/joss.01686.

[2] Y. Xie. xaringan: Presentation Ninja. R package version 0.16. 2020. URL: https://CRAN.R-project.org/package=xaringan.

19/20

Beyond Beamer

Modern and Dynamic Presentations with
R Markdown

Emi Tanaka

Department of Econometrics and Business Statistics

emi.tanaka@monash.edu @statsgen

30th Jun 2020 @ SSA NSW/Canberra x R-Ladies Sydney/Canberra | via Zoom

1/20
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