-
Notifications
You must be signed in to change notification settings - Fork 0
/
Intro_to_RMarkdown.Rmd
273 lines (135 loc) · 5.43 KB
/
Intro_to_RMarkdown.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
---
title: "Intro to R Markdown"
subtitle: "UCI Data Science Initiative"
author: "Dustin Pluta"
date: "May 12, 2017"
output:
xaringan::moon_reader:
seal: yes
nature:
highlightStyle: github
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
# Needed Packages
- `dplyr`
- `ggplot2`
- `shiny`
- `flexdashboard`
- `plotly`
- `stargazer`
## Optional Packages
- `biclust`
- `xaringan`
---
# Topics
1. Intro to R Markdown
2. Basic Syntax and Formatting
4. Advanced Formatting
5. Interactive Markdown Documents
---
# Some Resources for R
* [`dplyr` Cheat Sheet](https://www.rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf)
* [R Markdown Cheat Sheet](https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf)
* [R Markdown Tutorial](http://www.jacolienvanrij.com/Tutorials/tutorialMarkdown.html)
* [knitr](https://yihui.name/knitr/)
* [Data Carpentry Lessons for R](http://www.datacarpentry.org/R-ecology-lesson/)
* [dplyr Tutorial](http://genomicsclass.github.io/book/pages/dplyr_tutorial.html)
* [Advanced R (by Hadley Wickham)](http://adv-r.had.co.nz/)
* [R for Data Science (by Grolemund and Wickham)](http://r4ds.had.co.nz/)
---
# Intro to R Markdown
* __R Markdown__ is an implementation of the _Markdown_ markup language
* Markdown is a versatile tool that makes it easy to make readable scientific documents in a variety of formats
* R markdown is actively developed and supported by the RStudio team, which means:
+ RStudio has many tools and features to make R Markdown flexible and easy to use
+ New R Markdown features and packages are frequently released
---
# Intro to R Markdown
* __R For Data Science__ on the intent of R Markdown:
_R Markdown files are designed to be used in three ways:_
1. _For communicating to decision makers, who want to focus on the conclusions, not the code behind the analysis._
2. _For collaborating with other data scientists (including future you!), who are interested in both your conclusions, and how you reached them (i.e. the code)._
3. _As an environment in which to do data science, as a modern day lab notebook where you can capture not only what you did, but also what you were thinking._
---
# Getting Started with R Markdown
* R Markdown files end in `.Rmd`
* Create a new R markdown document in RStudio:
+ `File > New File > R Markdown...`
.center[<img src="Figures/Open_New_RMarkdown.png" height="400">]
---
# Getting Started with R Markdown
.center[<img src="Figures/Open_New_RMarkdown2.png" height="400">]
---
# Getting Started with R Markdown
* The default R Markdown template gives some examples of basic R Markdown features
.center[<img src="Figures/Open_New_RMarkdown3.png" height="500">]
---
# Getting Started with R Markdown
.center[<img src="Figures/EDIT1_Open_New_RMarkdown3.png" height="600">]
---
# Getting Started with R Markdown
.center[<img src="Figures/EDIT2_Open_New_RMarkdown3.png" height="600">]
---
# Getting Started with R Markdown
.center[<img src="Figures/EDIT3_Open_New_RMarkdown3.png" height="600">]
---
# Getting Started with R Markdown
.center[<img src="Figures/EDIT4_Open_New_RMarkdown3.png" height="600">]
---
# Getting Started with R Markdown
.center[<img src="Figures/EDIT5_Open_New_RMarkdown3.png" height="600">]
---
# Getting Started with R Markdown
.center[<img src="Figures/EDIT6_Open_New_RMarkdown3.png" height="600">]
---
# Getting Started with R Markdown
.center[<img src="Figures/EDIT7_Open_New_RMarkdown3.png" height="600">]
---
# Getting Started with R Markdown
* Compile or "knit" the R Markdown document to the desired format (either html, pdf, or Word document)
.center[<img src="Figures/EDIT_Open_New_RMarkdown4.png" height="300">]
---
# Getting Started with R Markdown
.center[<img src="Figures/Practice_First_Knit.png" height="500">]
---
# Getting Started with R Markdown
* Let's modify the plot to include a title, and make the points blue.
.center[<img src="Figures/EDIT_Open_New_RMarkdown5.png" height="400">]
---
# Getting Started with R Markdown
```{r pressure}
plot(pressure, main = "Plot Title", pch = 23, col = "blue", bg = "blue")
```
---
# Practice With R Markdown
[R Markdown Cheat Sheet](https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf)
1. R Markdown Basic Example: Shows simple plot with `cars` data set.
2. R Markdown Exercise Set 1: More examples and some exercises to try on the Iris and IMDB data sets.
---
# More R Markdown Features
1. Presentations: beamer, ioslides, slidy, xaringan
2. knitr
3. Blogdown
4. Bookdown
5. Interactive Documents
---
# Presentations
- You can easily create academic presentations using 4 different formats
+ beamer (pdf)
+ ioslides (html)
+ slidy (html)
+ xaringan (html)
.center[<img src="Figures/RMarkdown_Presentation.png" height="300">]
---
# knitr
- R Markdown can make full use of Latex through the `knitr` package
- `knitr` lets you easily display mathematical formulas and other Latex formatting in your Markdown document
- For example, math can be inserted inline like $\alpha^2 + \beta^2 = \gamma^2$ or in display mode:
$$Y = X \beta + \varepsilon$$
$$\int_{\mathbb{R}} \sum_{i = 1}^n \nabla \ell_i d\mu$$
---
# Blogdown
[Making a Website Using Blogdown, Hugo, and GitHub pages](https://proquestionasker.github.io/blog/Making_Site)/
[Example Blogdown Blog: Simply Statistics](https://simplystatistics.org)