-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_time-of-day.Rmd
124 lines (104 loc) · 4.47 KB
/
03_time-of-day.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
---
editor_options:
chunk_output_type: console
---
# Time of day analyses
In this script, we will assess if the time of day (1-hour segments) have an effect on the species richness.
## Install necessary libraries
```{r}
library(tidyverse)
library(dplyr)
library(stringr)
library(vegan)
library(ggplot2)
library(scico)
library(data.table)
library(extrafont)
library(ggstatsplot)
# Source any custom/other internal functions necessary for analysis
source("code/01_internal-functions.R")
```
## Load dataframe containing point count and acoustic data
```{r}
datSubset <- read.csv("results/datSubset.csv")
```
## Load species trait data
```{r}
trait <- read.csv("data/species-trait-dat.csv")
# add it to the subset data
datSubset <- left_join(datSubset,trait[,c(1,7,8)], by = "scientific_name")
```
## What times of day have been sampled across sites?
Here we get a sense of what times of day have been visited/sampled most across sites for point count data and acoustic surveys
```{r}
nSitesTime_pc <- datSubset%>%
filter(data_type == "point_count") %>%
dplyr::select(site_id, time_of_day)%>%
distinct() %>% arrange(time_of_day) %>%
count(time_of_day) %>%
mutate(data_type = "point_count")
nSitesTime_aru <- datSubset%>%
filter(data_type == "acoustic_data") %>%
dplyr::select(site_id, time_of_day)%>%
distinct() %>% arrange(time_of_day) %>%
count(time_of_day) %>%
mutate(data_type = "acoustic_data")
# This comparison lets us know that number of visits for the time_of_day - 9AM to 10AM is significantly different between acoustic data and point counts and we shall ignore this time segment when we carry out further analyses.
```
## Estimate richness by time of day
Here we will estimate species richness for different 1-hour segments with the expectation that richness/detections would differ between point counts and acoustic surveys.
```{r}
# point-count data
# estimate total abundance across all species for each site
abundance <- datSubset %>%
filter(data_type == "point_count") %>%
group_by(site_id, scientific_name,
common_name, eBird_codes, time_of_day) %>% summarise(totAbundance = sum(number)) %>%
filter(time_of_day != "9AM to 10AM") %>%
ungroup()
# estimate richness for point count data
pc_richness_time <- abundance %>%
mutate(forRichness = case_when(totAbundance > 0 ~ 1)) %>%
group_by(site_id, time_of_day) %>%
summarise(richness = sum(forRichness)) %>%
mutate(data_type = "point_count") %>%
ungroup()
# estimate total number of detections across the acoustic data
# note: we cannot call this abundance as it refers to the total number of vocalizations across a 16-min period across all sites
detections <- datSubset %>%
filter(data_type == "acoustic_data") %>%
group_by(site_id, scientific_name,
common_name, eBird_codes, time_of_day) %>% summarise(totDetections = sum(number)) %>%
filter(time_of_day != "9AM to 10AM") %>%
ungroup()
# estimate richness for acoustic data
aru_richness_time <- detections %>%
mutate(forRichness = case_when(totDetections > 0 ~ 1)) %>%
group_by(site_id, time_of_day) %>%
summarise(richness = sum(forRichness)) %>%
mutate(data_type = "acoustic_data") %>%
ungroup()
```
## Visualize differences in richness between point count data and acoustic data
```{r}
richness_time <- bind_rows(pc_richness_time, aru_richness_time)
# visualization for different times of day
fig_richness_by_time <- richness_time %>%
grouped_ggbetweenstats(x = data_type,
y = richness,
grouping.var = time_of_day,
xlab = "Data type",
ylab = "Richness",
pairwise.display = "significant",
package = "ggsci",
palette = "default_jco",
ggplot.component = list(theme(text = element_text(family = "Century Gothic", size = 15, face = "bold"),plot.title = element_text(family = "Century Gothic",
size = 18, face = "bold"),
plot.subtitle = element_text(family = "Century Gothic",
size = 15, face = "bold",color="#1b2838"),
axis.title = element_text(family = "Century Gothic",
size = 15, face = "bold"))))
ggsave(fig_richness_by_time, filename = "figs/fig_richness_by_time.png", width = 13, height = 10, device = png(), units = "in", dpi = 300)
dev.off()
```
