Skip to content

Commit

Permalink
Slides and demos for the webinar R Markdown ecosystem
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Oct 28, 2015
1 parent 376c0f1 commit eabd4a2
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 0 deletions.
Binary file not shown.
7 changes: 7 additions & 0 deletions 13-R-Markdown-Ecosystem/conditional-bad.Rmd
@@ -0,0 +1,7 @@
Darn it, the regression coefficient was not significant! Looks like I will have to go home by 2am tonight...

```{r echo=FALSE}
knitr::kable(b)
```

![](http://yihui.name/slides/images/sleepy.png)
7 changes: 7 additions & 0 deletions 13-R-Markdown-Ecosystem/conditional-good.Rmd
@@ -0,0 +1,7 @@
Oh yeah, the regression coefficient was significant! Time to go to Hawaii!!

```{r echo=FALSE}
knitr::kable(b)
```

![](http://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Lanikai_Strand_auf_Oahu.jpg/1920px-Lanikai_Strand_auf_Oahu.jpg)
44 changes: 44 additions & 0 deletions 13-R-Markdown-Ecosystem/conditional.Rmd
@@ -0,0 +1,44 @@
---
title: "Include Content Conditionally"
author: "Yihui Xie"
date: "January 16, 2015"
output:
html_document:
number_sections: yes
self_contained: no
---

# Introduction

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

# Data overview

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r}
par(mar = c(4, 4, .2, .1))
plot(cars, pch = 20)
```

# Model

Now we build a linear regression model:

```{r}
fit = lm(dist ~ speed, data = cars)
b = coef(summary(fit))
# b
```

# Conclusion

```{r child = if (b[2, 4] < 0.05) 'conditional-good.Rmd' else 'conditional-bad.Rmd'}
```

112 changes: 112 additions & 0 deletions 13-R-Markdown-Ecosystem/document.Rmd
@@ -0,0 +1,112 @@
---
title: "An R Markdown Document"
author:
- Li Lei
- Han Meimei
date: "2015/10/28"
output:
html_document:
fig_caption: yes
number_sections: yes
theme: cerulean
toc: yes
pdf_document: default
word_document: default
bibliography: references.bib
---

A bit _introduction_ here. We no longer need to start an article by writing this:

```latex
\documentclass{article}
\begin{document}
\end{document}
```

# Start with a cool section

You can use traditional **Markdown** syntax, such as [links](http://yihui.name/knitr) and `code`. Here is a quote:

> A girl phoned me the other day and said "Come on over, there's nobody home." I went over. Nobody was home. -- Rodney Dangerfield
# Followed by another section

Of course you can write lists:

- apple
- pear
- banana

Or ordered lists:

1. items
1. will
1. be
1. ordered
- nested
- items

# Okay, some R code

```{r linear-model}
fit = lm(dist ~ speed + I(speed^2), data = cars)
b = coef(fit) # coefficients
summary(fit)
```

The code will be highlighted in all output formats.

# And some pictures

```{r lm-vis, fig.cap='Regression diagnostics', fig.height=5}
par(mfrow = c(2, 2), pch = 20, mar = c(4, 4, 2, .1), bg = 'white')
plot(fit)
```

# A little bit math

Our regression equation is $Y=`r b[1]`+`r b[2]`x$, and the model is:

$$ Y = \beta_0 + \beta_1 x + \epsilon$$

# Pandoc extension: definition lists

Programmer
: A programmer is the one who turns coffee into code.
LaTeX
: A simple tool that is nothing but a couple of backslashes.

# Pandoc extension: examples

We have some examples.

(@) Think what is `0.3 + 0.4 - 0.7`. Zero. Easy.
(@weird) Now think what is `0.3 - 0.7 + 0.4`. Still zero?

People are often surprised by (@weird).

# Pandoc extension: tables

A table here.

Table: Demonstration of simple table syntax.

Right Left Center Default
------- ------ ---------- -------
12 12 12 12
123 123 123 123
1 1 1 1

# Pandoc extension: footnotes

We can also write footnotes[^1].

[^1]: hi, I'm a footnote

Or write some inline footnotes^[as you can see here].

# Pandoc extension: citations

We compile the R Markdown file to Markdown through **knitr** [@xie2013] in R [@R-base]. For more about @xie2013, see <http://yihui.name/knitr>.

# References
81 changes: 81 additions & 0 deletions 13-R-Markdown-Ecosystem/htmlwidgets.Rmd
@@ -0,0 +1,81 @@
---
title: "HTML Widgets"
author: "Yihui Xie"
date: "March 12, 2015"
output: html_document
---

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r, echo=FALSE}
plot(cars)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

# DataTables

```{r}
library(DT)
datatable(iris)
```

# Leaflet Maps

```{r}
library(leaflet)
m = leaflet() %>% addTiles()
m # a map with the default OSM tile layer
m = m %>% setView(-93.65, 42.0285, zoom = 17)
# popup
m %>% addPopups(-93.65, 42.0285, 'Here is the <b>Department of Statistics</b>, ISU')
rand_lng = function(n = 10) rnorm(n, -93.65, .01)
rand_lat = function(n = 10) rnorm(n, 42.0285, .01)
# use automatic bounds derived from lng/lat data
m = m %>% clearBounds()
# marker
m %>% addMarkers(rand_lng(), rand_lat())
```

# Dygraphs

```{r}
library(dygraphs)
dygraph(sunspots) %>% dyRangeSelector()
lungDeaths <- cbind(mdeaths, fdeaths)
dygraph(lungDeaths)
```

# Network graphs

```{r}
library(networkD3)
data(MisLinks, MisNodes)
str(MisLinks)
str(MisNodes)
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4)
```

# Three.js

```{r}
library(threejs)
data(world.cities, package="maps")
cities <- world.cities[order(world.cities$pop,decreasing=TRUE)[1:1000],]
value <- 100 * cities$pop / max(cities$pop)
earth <- texture(system.file("images/world.jpg",package="threejs"))
globejs(img=earth, lat=cities$lat, long=cities$long, value=value)
```
101 changes: 101 additions & 0 deletions 13-R-Markdown-Ecosystem/presentation.Rmd
@@ -0,0 +1,101 @@
---
title: "An R Markdown Document"
author:
- Li Lei
- Han Meimei
date: "2015/10/28"
output:
ioslides_presentation: default
beamer_presentation:
theme: AnnArbor
slidy_presentation: default
bibliography: references.bib
---

## Start with a cool section

You can use traditional **Markdown** syntax, such as [links](http://yihui.name/knitr) and `code`. Here is a quote:

> A girl phoned me the other day and said "Come on over, there's nobody home." I went over. Nobody was home. -- Rodney Dangerfield
## Followed by another section

Of course you can write lists:

- apple
- pear
- banana

Or ordered lists:

1. items
1. will
1. be
1. ordered
- nested
- items

## Okay, some R code

```{r linear-model}
fit = lm(dist ~ speed, data = cars)
b = coef(fit) # coefficients
summary(fit)
```

The code will be highlighted in all output formats.

## And some pictures

```{r lm-vis, fig.cap='Regression diagnostics'}
par(mfrow = c(2, 2), pch = 20, mar = c(4, 4, 2, .1), bg = 'white')
plot(fit)
```

## A little bit math

Our regression equation is $Y=`r b[1]`+`r b[2]`x$, and the model is:

$$ Y = \beta_0 + \beta_1 x + \epsilon$$

## Pandoc extension: definition lists

Programmer
: A programmer is the one who turns coffee into code.
LaTeX
: A simple tool that is nothing but a couple of backslashes.

## Pandoc extension: examples

We have some examples.

(@) Think what is `0.3 + 0.4 - 0.7`. Zero. Easy.
(@weird) Now think what is `0.3 - 0.7 + 0.4`. Still zero?

People are often surprised by (@weird).

## Pandoc extension: tables

A table here.

Table: Demonstration of simple table syntax.

Right Left Center Default
------- ------ ---------- -------
12 12 12 12
123 123 123 123
1 1 1 1

## Pandoc extension: footnotes

We can also write footnotes[^1].

[^1]: hi, I'm a footnote

Or write some inline footnotes^[as you can see here].

## Pandoc extension: citations

We compile the R Markdown file to Markdown through **knitr** [@xie2013] in R [@R-base]. For more about @xie2013, see <http://yihui.name/knitr>.

## References
18 changes: 18 additions & 0 deletions 13-R-Markdown-Ecosystem/references.bib
@@ -0,0 +1,18 @@
@book{xie2013,
title = {Dynamic Documents with {R} and knitr},
author = {Yihui Xie},
publisher = {Chapman and Hall/CRC},
address = {Boca Raton, Florida},
year = {2015},
edition = {2nd},
note = {ISBN 978-1498716963},
url = {http://yihui.name/knitr/}
}
@Manual{R-base,
title = {R: A Language and Environment for Statistical Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2013},
url = {http://www.R-project.org/},
}

0 comments on commit eabd4a2

Please sign in to comment.