Skip to content

Latest commit

 

History

History
110 lines (76 loc) · 3.17 KB

009-slides.md

File metadata and controls

110 lines (76 loc) · 3.17 KB

% Writing beautiful and reproducible slides quickly % Yihui Xie % 2012/04/30

Why

  • after you finished typing \documentclass{beamer} and \title{}, I have finished my first slide with markdown
  • much less 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

head(cars)
##   speed dist
## 1     4    2
## 2     4   10
## 3     7    4
## 4     7   22
## 5     8   16
## 6     9   10
cor(cars)
##        speed   dist
## speed 1.0000 0.8069
## dist  0.8069 1.0000

Graphics too

library(ggplot2)
qplot(speed, dist, data = cars) + geom_smooth()

A scatterplot of cars

How

  • source editor: RStudio (perfect integration with knitr; one-click compilation); currently you have to use the version >= 0.96.109
  • HTML5 slides converter: 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 is the markdown output from its source: 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? (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:

print(sessionInfo(), locale = FALSE)
## R version 2.15.2 (2012-10-26)
## Platform: x86_64-pc-linux-gnu (64-bit)
## 
## attached base packages:
## [1] methods   stats     graphics  grDevices utils     datasets  base     
## 
## other attached packages:
## [1] ggplot2_0.9.3 knitr_0.9.2  
## 
## loaded via a namespace (and not attached):
##  [1] colorspace_1.2-0   dichromat_1.2-4    digest_0.6.0      
##  [4] evaluate_0.4.3     formatR_0.7        grid_2.15.2       
##  [7] gtable_0.1.2       labeling_0.1       MASS_7.3-22       
## [10] munsell_0.4        plyr_1.8           proto_0.3-10      
## [13] RColorBrewer_1.0-5 reshape2_1.2.2     scales_0.2.3      
## [16] stringr_0.6.2      tools_2.15.2

Life is short

  • so keep your audience awake!