-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLPBO_Band_NC.R
107 lines (84 loc) · 3.11 KB
/
LPBO_Band_NC.R
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
##January 2025
##Danielle Ethier
#This code is for accessing and summarizing LBPO-BAND data from the NatureCounts database.
#To access these data, you will need to request permission for [email protected]
#Install packages
library(naturecounts)
library(tidyverse)
#You need to use the nc_query_table function to access the dataset
#To preview which data tables are available in the nc_query_tables package, use the following code:
nc_query_table(uername = "YOURUSERNAME") #you will be prompted for a password.
#You are looking to download the CmmnLpboBand table.
LPBO<-nc_query_table("CmmnLpboBand", username = "dethier")
#Create a spring and fall column
LPBO<-LPBO %>% mutate(season = ifelse(Mo %in% c(4, 5, 6, 7), "spring", ifelse(Mo %in% c(8, 9, 10, 11), "fall", "delete"))) %>% filter(season != "delete")
#Identify recapture birds by identifying Bandnum appearing more than once in the records
recap<-LPBO %>%
group_by(Bandnum) %>%
filter(n()>1) %>%
select(Spcd, Bandnum, day, Mo, Yr)
#make a list of recapture birds that do not share the same species code
recap2<-recap %>%
group_by(Bandnum) %>%
filter(n_distinct(Spcd)>1) %>%
select(Spcd, Bandnum, day, Mo, Yr)
#Make a summary of the number banded each Yr and season, including the number of recaptures
capsum<-LPBO %>%
group_by(Yr, season) %>%
summarise(n_banded=n(), n_recap=sum(duplicated(Bandnum))) %>%
arrange(Yr)
#fix errors and omissions in age and sex scores
LPBO<-LPBO %>% mutate(Age = case_when(
Alphaage == "U" ~ 0,
Alphaage == "HY" ~ 2,
Alphaage == "AHY" ~ 1,
Alphaage == "SY" ~ 5,
Alphaage == "ASY" ~ 6,
Alphaage == "L" ~ 4,
Alphaage == "TY" ~ 7,
Alphaage == "ATY" ~ 8
))
LPBO<-LPBO %>% mutate(Alphaage = case_when(
Age == 0 ~"UNK",
Age == 2 ~ "HY",
Age == 1 ~ "AHY",
Age == 4 ~ "L",
Age == 5 ~ "SY",
Age == 6 ~ "ASY",
Age == 7 ~ "TY",
Age == 8 ~ "ATY"
))
LPBO <-LPBO %>% mutate(Sex = case_when(
Alphasex == "U" ~ 0,
Alphasex == "F" ~ 5,
Alphasex == "M"~ 4
))
LPBO<-LPBO %>% mutate(Alphasex = case_when(
Sex == 0 ~ "U",
Sex == 4 ~ "M",
Sex == 5 ~ "F",
Sex == 6 ~ "U",
Sex == 7 ~ "U"
))
LPBO<-LPBO %>% filter(!(fat %in% c("I", "H", "23", "30.9", "9"))| is.na(fat))
#example of how to filter by a species list
sp.list<-c("WTSP", "SWTH", "OVEN", "REVI", "HETH", "MYWA", "RCKI", "NAWA", "MAWA", "BLPW")
sp.dat<-LPBO %>% filter(Spcd %in% sp.list)
#Make a summary of the number banded each Yr and season, including the number of recaptures
capsum2<-sp.dat %>%
group_by(Yr, season) %>%
summarise(n_banded=n(), n_recap=sum(duplicated(Bandnum))) %>%
arrange(Yr, season)
write.csv(capsum2, "LPBO_Band_NC.csv")
#filter data for Yr >= 1974
plot<-LPBO %>% filter(Yr >= 1974)
plot<-plot %>%
group_by(Yr, season) %>%
summarise(n_banded=n(), n_recap=sum(duplicated(Bandnum))) %>%
arrange(Yr, season)
#Create a ggplot point and line graph of the number of birds banded each year by season
p<-ggplot(plot, aes(x=Yr, y=n_banded, color=season))+
geom_point()+
geom_line()+
labs(title="Number of birds banded each year by season", x="Year", y="Number of birds banded")+
theme_minimal()