-
Notifications
You must be signed in to change notification settings - Fork 586
/
009-slides.Rmd
71 lines (48 loc) · 2.56 KB
/
009-slides.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
% Writing beautiful and reproducible slides quickly
% Yihui Xie
% 2012/04/30
```{r setup, include=FALSE}
# set global chunk options
library(knitr)
opts_chunk$set(cache=TRUE)
```
# Why
- after you finished typing `\documentclass{beamer}` and `\title{}`, I have finished my first slide with markdown
- far fewer commands to remember, e.g. to write bullet points, just begin with a dash "`-`" instead of `\begin{itemize}` and `\item`; how things can be simpler?
- I know you want math to show you are a statistician, e.g. $f(k)={n \choose k}p^{k}(1-p)^{n-k}$
- you do not need to maintain output -- only maintain a source file
- HTML5/CSS3 is much more fun than LaTeX
# A bit R code
```{r computing}
head(cars)
cor(cars)
```
# Graphics too
```{r graphics, message=FALSE, fig.cap='A scatterplot of `cars`', fig.width=11, fig.height=5, warning=FALSE}
library(ggplot2)
qplot(speed, dist, data = cars) + geom_smooth()
```
# How
- source editor: [RStudio](http://www.rstudio.org/) (perfect integration with [**knitr**](http://yihui.org/knitr/); one-click compilation); currently you have to use the version >= 0.96.109
- HTML5 slides converter: [pandoc](http://johnmacfarlane.net/pandoc/); this document was generated by: `pandoc -s -S -i -t dzslides --mathjax knitr-slides.md -o knitr-slides.html`
- the file [`knitr-slides.md`](https://github.com/yihui/knitr-examples/blob/master/009-slides.md) is the markdown output from its [source](https://github.com/yihui/knitr-examples/blob/master/009-slides.Rmd): `library(knitr); knit('knitr-slides.Rmd')`
- or simple click the button `Knit HTML` in RStudio
# For ninjas
- you should tweak the default style; why not try some [Google web fonts](http://www.google.com/webfonts)? (think how painful it is to wrestle with fonts in LaTeX)
- pandoc provides 3 types of HTML5 slides (dzslides is one of them)
- you can tweak the default template to get better appearances
- if you have come up with a better dzslides template, please let me know or contribute to pandoc directly (e.g. `pre` blocks should have `max-width` and `max-height`)
# For beamer lovers
- pandoc supports conversion to beamer as well. period.
# For Powerpoint lovers
- ...
# Reproducible research
It is good to include the session info, e.g. this document is produced with **knitr**. Here is my session info:
```{r session-info}
print(sessionInfo(), locale=FALSE)
```
# Misc issues
- the plots are too wide? use the chunk option `out.width` which will be used in `<img width=... />`, e.g. `out.width=400px`
# Life is short
- so keep your audience awake!
![](http://i.imgur.com/qBO9K.jpg)