Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slides and demos for the webinar R Markdown ecosystem
- Loading branch information
Showing
8 changed files
with
370 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/}, | ||
} |