@@ -14,104 +14,109 @@ language: R
14
14
15
15
### Getting started
16
16
17
- * Open RStudio
17
+ * ` install.packages("rmarkdown") ` in console for permanence
18
18
* ` File ` -> ` New File ` -> ` R Markdown `
19
19
* Enter a title and author(s).
20
20
* Choose 'Default Output Format' as ` HTML ` .
21
21
* Generates a basic stub of a ` .Rmd ` document
22
- * Customize "front matter" at the top of the document between the ` --- ` .
23
- * Press ` Knit ` to create an ` HTML ` from the document
24
- * 1st time may ask you to install some packages
25
- * ` install.packages("rmarkdown") ` in console for permanence
26
- * Runs the code in the code chunks and prints their output along with the
27
- markdown formatted text
28
- * Can also create ` PDF ` & Word versions of our files
29
- * ` PDF ` Requires ` pandoc ` and ` TeX ` installation
30
- * Use the ` Knit ` dropdown or change ` output: pdf_document `
31
- * R Notebook
32
- * ` output: html_notebook `
33
- * "Interactive R Markdown"
34
- * execute individual code chunks
35
- * output in editor pane
22
+ * Customize "front matter" at the top of the document between the ` --- ` .
23
+ * Delete everything below the second ` --- `
36
24
37
25
### Markdown
38
26
39
27
* Basic approach to formatting text
40
28
* Let's you do
29
+ * ` # Headers `
41
30
* ` *italics* `
42
31
* ` **bold** `
43
32
* ` [links](http://google.com) `
44
33
* Lists
45
34
* ` * `
46
35
* ` 1. `
47
- * ` # Header `
36
+
37
+
38
+ <pre ><code >
39
+ ## Concept
40
+
41
+ Exploration of population dynamic patterns at **The Portal Project**.
42
+ How do counts of rodents like *Dipodomys* species change through time?
43
+
44
+ In this document I will:
45
+
46
+ 1. Load data from the [Portal Project Teaching Database](http://figshare.com/articles/Portal_Project_Teaching_Database/1314459)
47
+ 2. Process it into population time series
48
+ 3. And make initial visualizations
49
+ </code ></pre >
50
+
48
51
* Easy to read for humans
49
52
* Easy to convert into other things for computers
50
- * Common on lots of websites
53
+
54
+ * Press ` Knit ` to create ` HTML ` from the document
55
+ * Can also create ` PDF ` & Word versions of our files
56
+ * ` PDF ` Requires ` pandoc ` and ` TeX ` installation
57
+ * Use the ` Knit ` dropdown or change ` output: pdf_document `
58
+
59
+ * Markdown is common on lots of websites
51
60
* Used to create all of the exercises and lectures in this course
52
61
* Github will automatically render it
53
62
* [ https://github.com/ethanwhite/CV/blob/master/CV.md ] ( https://github.com/ethanwhite/CV/blob/master/CV.md )
54
63
55
- < pre >< code >Explore patterns in population dynamics at Portal.
64
+ ### R chunks
56
65
57
- ## Required Libraries</code ></pre >
66
+ * R Markdown allows you to include code to run in the document
67
+ * Click on ` Insert ` and choose R
58
68
59
- ### R chunks
69
+ <pre ><code >
70
+ ## Required Packages
60
71
61
- * Set R code inside a set of <code >```</code > with the ` {r} ` designation
72
+ ```{r}
73
+ library(dplyr)
74
+ library(ggplot2)
75
+ ```
76
+ </code ></pre >
62
77
63
- <pre ><code >```{r}
64
- ```</code ></pre >
65
78
66
- * Code that you write inside chunks gets executed during the "knit" process and
67
- the results are shown below.
79
+ * Knitting runs the code and prints its output
68
80
69
- <pre ><code >```{r}
70
- library(dplyr)
71
- ```</code ></pre >
81
+ <pre ><code >
82
+ ## Data
83
+
84
+ ```{r}
85
+ data <- read.csv("https://ndownloader.figshare.com/files/2292172")
86
+ head(data)
87
+ ```
88
+ </code ></pre >
89
+
90
+
91
+ ### Chunk options
72
92
73
93
* Chunks have lots of useful options
74
94
* Options are described at: [ http://yihui.name/knitr/options/ ] ( http://yihui.name/knitr/options/ )
75
95
* Options will be listed in RStudio if you press tab inside
76
96
the ` {r} ` brackets at the top of the chunk
77
97
78
- <pre ><code >```{r, message=FALSE}
79
- library(dplyr)
80
- ```</code ></pre >
81
-
82
98
<pre ><code >```{r, message=FALSE}
83
99
library(dplyr)
84
100
library(ggplot2)
85
101
```</code ></pre >
86
102
87
- <pre ><code >```{r, message=FALSE, warning=FALSE}
88
- library(dplyr)
89
- library(ggplot2)
103
+ * ` cache=TRUE ` reuses results of the code chunk in subsequent "knits". Save time
104
+ re-calculating or re-downloading it each time.
105
+
106
+ <pre ><code >```{r, cache=TRUE}
107
+ data <- read.csv("https://ndownloader.figshare.com/files/2292172")
108
+ head(data)
90
109
```</code ></pre >
91
110
92
111
* You can run code inside your text, too:
93
- * <code >` r cos(pi) ` </code > turns into ` -1 ` when you press the ` Knit ` button.
94
- * We will see and example of this later.
95
-
96
- ### Analysis Report Example
97
-
98
- * Here's a text segment linked to a code chunk that begins an analysis report.
99
112
100
- <pre ><code >## Data
101
-
102
- Data is from the [Portal project teaching database](http://figshare.com/articles/Portal_Project_Teaching_Database/1314459)
103
- published on Figshare. We need the surveys table for our analysis:
104
-
105
- ```{r, cache=TRUE}
106
- download.file("https://ndownloader.figshare.com/files/2292172",
107
- "surveys.csv")
108
- data <- read.csv("surveys.csv")
109
- ```</code ></pre >
113
+ ```
114
+ The data includes `r length(unique(data$species_id))` species.
115
+ ```
110
116
111
- * Setting ` cache=TRUE ` lets you reuse the results of this code chunk in
112
- subsequent "knits" instead of re-calculating or re-downloading it each time.
117
+ ### Analysis Example
113
118
114
- <pre ><code >## Analyze population time-series
119
+ <pre ><code >## Analysis
115
120
116
121
Get the time-series of counts for all species.
117
122
@@ -120,6 +125,7 @@ time_series <-
120
125
data %>%
121
126
group_by(species_id, year) %>%
122
127
summarize(count = n()) %>%
128
+ filter(species_id %in% c('DM', 'DO', 'DS')) %>%
123
129
na.omit()
124
130
125
131
head(time_series)
@@ -133,31 +139,19 @@ head(time_series)
133
139
ggplot(time_series, aes(x = year, y = count)) +
134
140
geom_point() +
135
141
geom_line() +
136
- facet_wrap(~species_id ) +
137
- scale_x_continuous(breaks = pretty_breaks(n=2) )
138
- ```
142
+ geom_smooth( ) +
143
+ facet_wrap(~species_id )
144
+ ```</ pre ></ code >
139
145
140
- ## A simple model
146
+ ### Notebook
141
147
142
- ```{r, echo=FALSE}
143
- model <- data %>% group_by(year) %>%
144
- summarize(count = n()) %>%
145
- lm(count ~ year, data = .)
148
+ * In RStudio run chunks using ` Ctrl-Shift-Enter ` or ` Cmd-Shift-Enter `
149
+ * Displays results in the editor
146
150
147
- results <- anova(model)
148
- ```</code ></pre >
149
-
150
- * Here's the example of an inline code chunk.
151
+ * Notebook
151
152
152
- <pre ><code >We found a marginally significant linear relationship between the
153
- total count and year (p = `r round(results[["Pr(>F)"]][1], 3)`; see
154
- Table 1 for more details)
153
+ * ` output: html_notebook ` or File -> New File -> R Notebook
155
154
156
- ```{r, echo=FALSE}
157
- knitr::kable(results, caption = "Table 1")
158
- ```</code ></pre >
159
-
160
- * ` knitr::kable() ` is a handy way to make nice-looking tables from data frames.
161
155
162
156
### R Presentations
163
157
@@ -173,6 +167,7 @@ author:
173
167
date:
174
168
autosize: true
175
169
170
+
176
171
First Slide
177
172
========================================================
178
173
0 commit comments