/
challenge_slides.Rmd
194 lines (97 loc) · 3.58 KB
/
challenge_slides.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
---
output: slidy_presentation
---
# Challenge 1
Using pipes, subset the data to include individuals with weight less than 5,
and retain the columns `year`, `sex`, and `weight.`
---
# Challenge 2
Create a new dataframe from the survey data that
- contains only the `species_id` column and a column
with the square-root of `hindfoot_length` values (e.g. a new column
`hindfoot_sqrt`).
- also, for the `hindfoot_sqrt` column, all values are < 3.
---
# Challenge 3
How many times was each `plot_type` surveyed?
---
# Challenge 4
Use `group_by()` and `summarize()` to find the min and max hindfoot
length for each species.
---
# Challenge 5
Prepare three data sets for the data visualization session:
1. **`just_dm`** containing only the observations from with `species_ID == "DM"`
2. **`stat_summary`** containing the average weight and hindfoot length
for each species, as well as a count of the number of observations
for each species (using the `n()` function).
3. **`year_summary`** containing the yearly average weight, hindfoot
length, and count data for each species and sex combination.
(Hint, you only need to change the `group_by()` part from #2 to do
this.)
---
# Challenge 6
Make a scatterplot of `hindfoot_length` vs `weight`, but only for the
`species_id` `"DM"`.
- Use the dataset we'd created, `just_dm`
- Use our ggplot2 code above but with this new dataset in place of `surveys`.
---
# Challenge 7
Make a scatterplot of mean `hindfoot_length` vs mean `weight`, where
each point is a species, and where the sizes of points indicate the
sample size.
- Use the dataset we'd created, `stat_summary`
- Use our ggplot code with the aesthetics
`x=mean_wt` and `y=mean_hfl`, plus `size=n`.
---
# Challenge 8
- Use the `year_summary` dataset to make a line plot of counts of each
species by year, with a different colored line for each species.
- Use `aes(linetype=sex)` to have different line types for the two
sexes.
---
# Challenge 9
A variant on the box plot is the violin plot. Use `geom_violin()` to
make violin plots of `hindfoot_length` by `species_id`.
---
# Challenge 10
Try using `geom_histogram()` to make a histogram visualization of the
distribution of `weight`.
Hint: You want `weight` as the x-axis aesthetic. Try specifying `bins`
in `geom_histogram()`.
---
# Challenge 11
Use the `year_summary` dataset and make scatterplots of mean hindfoot
length vs mean weight (with each point being a species), faceting by year.
- Use aesthetics `x=mean_wt` and `y=mean_hfl`
- Use `geom_point(aes(color=species_id, shape=sex))`
- Use `facet_wrap(~ year)`
---
# Challenge 12
- Create a new R Markdown document.
- Delete all of the R code chunks and write a bit of Markdown (some sections, some italicized
text, and an itemized list).
- Convert the document to a webpage.
---
# Challenge 13
Add code chunks to
- Load the ggplot2 package
- Read the portal data
- Create a plot
---
# Challenge 14
Use chunk options to control the size of a figure and to hide the
code.
---
# Challenge 15
Try out a bit of in-line R code.
# Capstone project
Create and compile an R Markdown report:
1. Load the `portal_clean.csv` data.
2. Create boxplots of weight by sex.
3. Create a histogram of hindfoot lengths.
4. Create a scatterplot of hindfoot length vs weight for the species
`"DM"`, `"DO"`, and `"DS"`. _Use different colors for the three
species, and put the three species in different panels._
5. Create a line plot of the counts of `"DM"` in `"Rodent Exclosure"` plots over time.
6. Create a table of counts of `"DM"` by plot type for the year 1977.