-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial_2.Rmd
More file actions
378 lines (276 loc) · 19.6 KB
/
Tutorial_2.Rmd
File metadata and controls
378 lines (276 loc) · 19.6 KB
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
---
title: "Sexual Dimorphism and Sexual Selection Tutorial"
author: "Elizabeth Houghton and Kirsten Palmier"
output: html_document
---
```{r setup, include=FALSE}
# DO NOT ALTER CODE IN THIS CHUNK
knitr::opts_chunk$set(echo = TRUE)
```
```{r, include=FALSE}
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
packages <- c("ggplot2", "ggpubr", "dplyr", "tidyr", "lubridate", "reshape", "readr", "vembedr")
ipak(packages)
```
* * *
## Tutorial learning objectives
In this tutorial you will explore:
- Whether sexual dimorphism is present in a population of Tree Swallows found in Long Point, Ontario
- Life history traits of Tree Swallow
- Trade offs between the number of clutches a bird may have and the number of eggs in each clutch
- How the sampled population of Tree Swallow's birth rates have changed over time
* * *
## Background of datasets
This is a tutorial to get you familiar with R and explore ecological concepts through a Tree Swallow nest productivity dataset. Before we jump into the weeds, let's get to know our dataset!
The Tree Swallow (*Tachycineta bicolor*) is one of the most common birds in eastern North America that normally nests in tree cavities excavated by other species like woodpeckers, but also readily accepts human made nest’ boxes. Based on this quality and their abundance, Birds Canada has monitored nest boxes of tree swallows around the Long Point Biosphere Reserve, Ontario, from 1974 to 2014. Each year, May through June, volunteer research assistants check nest box contents daily, and band the adults and their young. Nest-box records are available from about 300 boxes from 3-4 sites during this period. Data collected includes nest box observations, clutch initiation dates, clutch size and egg weight, nest success, weather, insect abundance, and banding data. This data set includes all data entry related to eggs, nests, nestlings, nest check observations, and banding data from 1977 to 2014. More information on this dataset can be found [here]("https://figshare.com/articles/dataset/Tree_Swallow_Nest_Box_Productivity_Dataset_from_Long-Point_Ontario_Canada_1977-2014_/14156801/1?file=26736347").
Additionally, in 2021, this dataset was quality checked and made open access by Jonathan Diamond through a Data Rescue internship with the [Living Data Project]("https://www.ciee-icee.ca/data.html"), an initiative through the Canadian Institute of Ecology and Evolution that rescues legacy datasets.

Through Bird Studies Canada, Long Point Bird Observatory monitored three nest box "colonies" of Tree Swallows at Long Point, two on the "mainland" near Port Rowan (at the Port Rowan sewagelagoons and adjacent to agricultural land at mudd creek) and the third at the tip of the
Point.
<br>
<center>

</center>
<br>
### The Point
This colony was established in its present location in 1969. The nest boxes are located about 1 kmwest of the Tip of the point and are arranged 24.4m apart in a grid of numbered (north-south) rows and lettered (east-west) columns. Each box is designated by its position, so box 10G is in row 10 and column G. At the present time the rows in use are 1-19 and the letters are D-K, but many positions are unfilled and there are a total of 64 boxes.
<br>
<center>

</center>
<br>
### The Sewage Lagoon
This colony was first established in 1977 and has since been expanded to a total of 77 boxes. The boxes are in two rows around the lagoon embankment, as well as across the street in a small cluster of 5 boxes.
<br>
<center>

</center>
<br>
### Mud Creek
Established in 1987, the Mud Creek site is located 3.25 km north-northeast of Sewage Lagoon and contains 80 nest boxes. The habitat is an open, uncultivated field adjacent to a small woodlot.
<br>
<center>

</center>
<br>
For this tutorial we will be looking at the banding dataset which adults were trapped sometime between the first young hatch and when they were 12 days old. All adult birds are banded, unless previously banded. It was also recorded if the bird had a brood patch (BP) or cloacal protuberance (CP). Plumage color was recorded as blue (BLU), Brown (BRN), or Intermediate (INT). Furthermore, plumage categories and age/sex designations were assigned and a variety of size measurements were taken:
*Plumage Categories*
- BLU birds (ASY) – More than 90% of the upper parts iridescent blue-green
- INT birds (AHY) – More than 50% up to 90% of upper parts iridescent blue-green (remainder dull brown or brown tinged with green)
- BRN birds (SY) – Up to 50% of upper parts iridescent blue-green (remainder > 50% dull brown or brown tinged with green)
*Sex Categories*
- Male = M
- Female = F
*Measurements of Size and Weight*
- Wing chord length (mm) = wing_chord
- Wing chord flat (mm) = wing_flat
- Tail length (mm) = tail
- p_9 = primary feather length

Adults are blue-green above with white below with blacking flight feathers. Photo courtesy of Max Nootbaar from the [Macaulay Library]("https://macaulaylibrary.org/asset/101318791?__hstc=75100365.4b6645b395fc517502f8f060b03fdb13.1649426500778.1649426500778.1649426500778.1&__hssc=75100365.2.1649426500779&__hsfp=1238073771&_gl=1*1fqca32*_ga*NzI0MDM2MjY1LjE2NDk0MjY0OTg.*_ga_QR4NVXZ8BM*MTY0OTQyNjQ5OS4xLjEuMTY0OTQyNjU3Ny41OA..#_ga=2.227763358.2003098112.1649426500-724036265.1649426498").

First year females may be brownish above with hints of blue-green; adult females can be nearly blue-green as males. Photo courtesy of Matt Davis from the [Macaulay Library]("https://macaulaylibrary.org/asset/237909411?__hstc=75100365.4b6645b395fc517502f8f060b03fdb13.1649426500778.1649426500778.1649426500778.1&__hssc=75100365.3.1649426500779&__hsfp=1238073771&_gl=1*1n9uq65*_ga*NzI0MDM2MjY1LjE2NDk0MjY0OTg.*_ga_QR4NVXZ8BM*MTY0OTQyNjQ5OS4xLjEuMTY0OTQyNjg0Ni4yNg..#_ga=2.119171210.2003098112.1649426500-724036265.1649426498").
* * *
## Importing data and packages
In this tutorial, we will be working with Tree Swallow data collected by Bird Studies Canada, Long Point Bird Observatory as well as a few additional packages. Run the following code to import the required packages and pull in the dataset that we will be working with throughout this tutorial.
```{r echo = TRUE, warnings = FALSE, message = FALSE}
library(dplyr)
library(ggplot2)
library(tidyr)
library(lubridate)
library(reshape)
library(readr)
library(ggpubr)
# Here we are pulling the actual datasets into R
banding <- read.csv("TRES/banding_final.csv")
banding_nest <- read.csv("TRES/banding_nest_final.csv")
nest <- read.csv("TRES/nest_final.csv")
```
```{r echo = TRUE}
# Now, we want to make sure the class of our data is correct before we move forward:
str(banding)
# lets go ahead and convert the sex and nest_box column class into factors:
banding$sex <- as.factor(banding$sex)
banding$nest_box <- as.factor(banding$nest_box)
str(banding_nest)
# fix class
banding_nest$sex <- as.factor(banding_nest$sex)
banding_nest$nest_box <- as.factor(banding_nest$nest_box)
banding_nest$location <- as.factor(banding_nest$location)
str(banding_nest)
# fix class
nest$nest_code <- as.factor(nest$nest_code)
nest$location <- as.factor(nest$location)
```
* * *
## Sexual dimorphism in Tree Swallows
**Sexual dimorphism** is defined as the phenotypic variations within different sexes of the same species ( [Andersson and Iwasa 1998]("https://pubmed.ncbi.nlm.nih.gov/21237761/")). Differences can include size, weight, plumage (in birds). These differences are thought to arise through species that are part of a social mating system, in which there may be varying degrees of parental care ( [Darwin 1871]("http://darwin-online.org.uk/converted/pdf/1889_Descent_F969.pdf"); [Wallace 1889]("https://www.cambridge.org/core/books/darwinism/8BFFDD9B0F921EAF820ED6AF062D0CF7"); [Andersson and Iwasa 1998]("https://pubmed.ncbi.nlm.nih.gov/21237761/") ). This phenomenon is often seen in birds, where males are the larger sex and have more ornate plummage than females.
<img src="TRES/ornate.png" />
Image from [ThoughtCo.]("https://www.thoughtco.com/peacock-facts-4690664").
***
**Questions**
*Why do you think this phenomenon happens?*
*Why are females generally more drab?*
*In which instance to you think females would be more ornate than males? Can you think of some examples?*
***
To determine if **sexual dimorphism** exists in this tree swallow data were will get you to explore the average size measurements taken for each bird. Since birds were tracked using a band number, and birds may have been captured multiple times throughout their life, so we will observe the differences in average size measurement taken for each bird.
```{r echo = TRUE}
# look at the following variable to see how they differ by gender : wing_chord, tail, and weight
# will will take the mean of these measurements by band_number and gender
wing_chord <- aggregate(wing_chord ~ band_number + sex, banding, mean)
# Boxplot of these trends based on sex
ggplot(wing_chord, aes(factor(sex), wing_chord, fill=sex)) +
geom_boxplot() +
scale_fill_manual("", values=c("M"= "lightskyblue", "F"= "plum3")) +
xlab('') +
ylab('Wing Chord Length (mm)') +
ggtitle("Wing Chord Length vs. Sex")
```
Nice job! It looks like there is a difference between males and females in terms of wing chord measurements. Before moving forward, try measuring tail length and weight on your own. You'll see we have included what your graphs *should* look like below for both tail and weight means by sex.
**Hint** Look at the example we just ran using the **aggregate** function first, then plot with **ggplot**.
```{r echo = FALSE}
# Lets go ahead and try calculating the mean tail length and weight by sex and band number and graph boxplots of these values:
#### these are the answers ###
tail <- aggregate(tail ~ band_number + sex, banding, mean)
weight <- aggregate(weight ~ band_number + sex, banding, mean)
ggplot(tail, aes(factor(sex), tail, fill=sex)) +
geom_boxplot() +
scale_fill_manual("", values=c("M"= "lightskyblue", "F"= "plum3")) +
xlab('') +
ylab('Tail Length (mm)') +
ggtitle("Tail Length vs. Sex")
ggplot(weight, aes(factor(sex), weight, fill=sex)) +
geom_boxplot() +
scale_fill_manual("", values=c("M"= "lightskyblue", "F"= "plum3")) +
xlab('') +
ylab('Weight (g)') +
ggtitle("Bird Weight vs. Sex")
```
Now, to get a sense of how much the wind chord length, tail length, and weight differs between male and female tree swallows lets find the mean value for each.
```{r echo = TRUE}
# can calculate the mean female and male wing flat length like this (using aggregate()) or could subset by sex and then calculate
wing_chord.avg <- aggregate(wing_chord ~ sex, wing_chord, mean)
wing_chord.avg
```
Calculate the tail and weight average on your own. Cross reference your calculations with the ones below.
```{r echo = FALSE}
tail.avg <- aggregate(tail ~ sex, tail, mean)
weight.avg <- aggregate(weight ~ sex, weight, mean)
tail.avg
weight.avg
```
Before we head to our next section, check out this ornate mating dance between males and female birds of paradise. Note the sexual dimorphism between the males and females!
```{r echo = FALSE, message = FALSE}
library(vembedr)
embed_url("https://www.youtube.com/watch?v=nPhVOZiPokA")
```
***
**Questions**
*What is the average wing chord length, tail length, and weight of the male tree swallows?*
*What is the average wing chord length, tail length, and weight of the female tree swallows?*
*Do these findings suggest that there is some level of sexual dimorphism in tree swallows?*
*What type of pressures could lead to sexual dimorphism in tree swallows?*
***
* * *
## Aspects of Tree Swallow Life History
How and why do organisms evolve over time? How does natural selection, and other evolutionary forces, shape organisms over time so that they are more likely to survive and reproduce? These are some pretty big questions that *Life History Theory* tries to answer. Although we won't dive into all aspects of life history with our Tree Swallow datasets, we will explore some possible connections including: trade-offs between clutch size and clutch number, whether or not bigger birds produce larger clutches, and if clutch sizes have changed over time.
### Trade-offs: Clutch size vs. clutch number?
Trade-offs exist when "*an increase in one life history trait (improving fitness) is coupled to a decrease in another life history trait (reducing fitness), so that the fitness benefit through increasing trait 1 is balanced against a fitness cost through decreasing trait 2*" [Fabian and Flatt, 2012]("https://www.nature.com/scitable/knowledge/library/life-history-evolution-68245673/"). Traits can either be described as negative phenotypic, or genetic correlations between fitness components of individuals in a given population. Trade-offs are generally caused by limited resources, and competition for these resources, to one life history trait verses the other within an individual. For example, an organism might have a relatively short lifespan--but produce many offspring, or vice versa (think about mayflies vs. elephants for example).
<img src="TRES/trade_offs.png" />
**Life history trade-offs**:
(A): A negative genetic (or phenotypic) correlation, i.e. a trade-off, between reproduction (e.g., # of eggs produced) and adult survival, one of the most commonly found negative relationships between life history traits.
(B) The so-called Y model of resource allocation trade-offs. In this example, a limited resource (e.g., a nutrient) is aquired and differentially (competitively) allocated (invtested) into physiological processes that affect survival at the expense of investment into reproductive functions (e.g., egg production, fecundity).
(C) A useful way of thinking about resource allocation trade-offs is to imagine the life history as being a finite pie.
(Image from [Fabian and Flatt 2012]("https://www.nature.com/scitable/knowledge/library/life-history-evolution-68245673/"))
```{r echo = TRUE}
# to visualize whether there may be a trade off between clutch size and the number of clutches in a nest lets visualize these factors in a box plot
# the 'nest' dataset contains records of the clutch numbers found in nest boxes across Long Point dating back to 1987!
# lets take a quick look at the dataset first to figure out what we need to plot
head(nest)
# we want to look at how clutch size (clutch_size) may vary between the first and second clutch (clutch_number)
ggplot(nest, aes(factor(clutch_number), clutch_size)) +
geom_boxplot(outlier.colour="black", outlier.size=0.5, position = position_dodge(preserve = "single")) +
xlab('Clutch Number') +
ylab('Clutch Size') +
ggtitle("Clutch Size vs. Clutch Number") +
scale_y_continuous(breaks = seq(0, 13, by = 1)) +
theme(plot.title = element_text(hjust = 0.5))
# example on how to calculate the average clutch size for clutch number 1 and 2
aggregate(clutch_size ~ clutch_number, nest, mean )
```
***
**Question**
*What is the average clutch size for the first and second clutches?*
You may have noticed that the second clutches are slightly smaller than the first clutches! However, in order to confirm that there is a statistically significant difference between the two clutch sizes you would need to complete some sort of statistical analysis (e.g a t-test).
***
### Do larger birds have bigger clutches?
Is the size and weight of the bird at maturity related to the clutch size? Lets look at wing chord length, tail length, and bird weight to investigate this and lets separate our analysis my male and female birds
```{r echo = TRUE}
# First, lets find the mean wing chord length when grouped by year, nest_box, sex, clutch_number, clutch_size and band number
# wing_chord
banding_nest.wing_chord <- aggregate(wing_chord ~ year + sex + nest_box + clutch_number + band_number + clutch_size, banding_nest, mean)
head(banding_nest.wing_chord)
# lets see if we see any patterns between the number of eggs there are per clutch (clutch_size) and the weight or size of the parent tree swallow
plot(clutch_size ~ wing_chord, banding_nest.wing_chord,
main="Clutch Size vs Parent Wing Chord Length",
pch=20,
col=sex,
xlab="Wing Chord Length (mm)",
ylab="Clutch Size")
legend("topright", legend= levels(banding_nest.wing_chord$sex),
col= 1:2, pch = 20, cex=0.9)
```
Now, you look at tail and weight variables. Compare your results to the results below.
**Hint** Use similar code to the code above, but change the variables to reflect what you are intersted in looking at.
```{r echo = FALSE}
# tail
banding_nest.tail <- aggregate(tail ~ year + sex + nest_box + clutch_number + band_number + clutch_size, banding_nest, mean)
# weight
banding_nest.weight <- aggregate(weight ~ year + sex + nest_box + clutch_number + band_number + clutch_size, banding_nest, mean)
plot(clutch_size ~ tail, banding_nest.tail,
main="Clutch Size vs Parent Tail Length",
pch=20,
col=sex,
xlab="Tail Length (mm)",
ylab="Clutch Size")
legend("topright", legend= levels(banding_nest.tail$sex),
col= 1:2, pch = 20, cex=0.9)
plot(clutch_size ~ weight,banding_nest.weight,
main="Clutch size vs Parent Bird Weight",
pch=20,
col=sex,
xlab="Weight (g)",
ylab="Clutch Size")
legend("topright", legend= levels(banding_nest.weight$sex),
col= 1:2, pch = 20, cex=0.9)
```
* * *
## Changes through time
Could bird communities be changing over time as a result of climate change or other environmental shifts? Lets observe if the average clutch size over time is changing.
```{r echo = TRUE}
# first we want to take the average clutch size that was sampled from all of the nest boxes each year
nest.average <- aggregate(clutch_size ~ year, nest, mean)
#Then, we'll run a linear regression to test the relationship between clutch size and year.
lm_clutch_size <- summary(lm(clutch_size ~ year, data= nest.average))
r2_0 <- lm_clutch_size$r.squared # for R-squared labels
rlabel_0 <- bquote(italic(R)^2 == .(format(r2_0, digits = 3)))
plot(clutch_size ~ year, data=nest.average,
main="Yearly Average Clutch Size over Time",
pch=16,
xlab="Year",
ylab="Yearly Average Clutch Size",
cex.main=1.25,
cex.lab=1)
abline(lm(clutch_size ~ year, data=nest.average))
text(2010, 6.2, rlabel_0)
```
It may appear that the average clutch size is declining overtime however when looking at the R^2 value of this linear regression we can see that this relationship is not a strong one.
* * *
## Take-homes
After going through these data you have now had the opportunity to learn a bit about tree swallows, and more specifically look at a 'community' of tree swallows found in Long Point, ON. This population appeared to show signs of sexual dimorphism, where the male swallows had longer wing chords and tails and were heavier. As well, we noticed that there appeared t be a trade off between clutch size and the number of clutched in a nest. An important thing to not is that these relationships were speculative and statistical analyses will be required to support these findings in this population.
Lastly, these data did not show trends of larger birds having more eggs and we observed no conclusive temporal trends of changes in birth rates over time. It is not uncommon that data is collected with certain hypotheses in mind and trend or relationships are ultimately not found to support these hypotheses!