-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch_analysis.R
146 lines (124 loc) · 6.48 KB
/
ch_analysis.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
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
tar_load(c(og_by_district, ch_by_district, faib_by_district,
og_ch_by_district, faib_og_ch, prot_ch_by_district))
nat_res_area <- bcmaps::nr_districts() %>%
mutate(district_area = st_area(.),
district_area =as.numeric(set_units(district_area, ha))) %>%
st_set_geometry(NULL) %>%
rename_all(tolower) %>%
group_by(district_name) %>%
summarise(district_area = sum(district_area)) %>%
ungroup()
write_csv(nat_res_area, "nat_res_area.csv")
og_district <- og_by_district %>%
mutate(og_district_area = st_area(.),
og_district_area =as.numeric(set_units(og_district_area, ha))) %>%
st_set_geometry(NULL) %>%
rename_all(tolower) %>%
group_by(district_name) %>%
summarise(og_district_area = sum(og_district_area)) %>%
ungroup()
faib_district <- faib_by_district %>%
mutate(faib_district_area = st_area(.),
faib_district_area =as.numeric(set_units(faib_district_area, ha))) %>%
st_set_geometry(NULL) %>%
rename_all(tolower) %>%
group_by(district_name) %>%
summarise(faib_district_area = sum(faib_district_area)) %>%
ungroup()
district_output <- prot_by_district %>%
mutate(og_prot_district_area = st_area(.),
og_prot_district_area =as.numeric(set_units(og_prot_district_area, ha))) %>%
st_set_geometry(NULL) %>%
rename_all(tolower) %>%
group_by(district_name) %>%
summarise(og_prot_district_area = sum(og_prot_district_area)) %>%
ungroup() %>%
left_join(nat_res_area) %>%
left_join(og_district) %>%
left_join(faib_district) %>%
mutate(og_perc = og_district_area/district_area*100,
prot_perc = og_prot_district_area/og_district_area *100,
at_risk_area = og_district_area - og_prot_district_area,
at_risk_perc = faib_district_area/og_district_area *100,
og_index = at_risk_perc/og_perc
)
write_csv(district_output, "og-prot_nat-res-area.csv")
og_ch <- og_ch_by_district %>%
mutate(og_species_area = st_area(.),
og_species_area =as.numeric(set_units(og_species_area, ha))) %>%
st_set_geometry(NULL) %>%
rename_all(tolower) %>%
group_by(scientific_name, common_name_english, cosewic_status, schedule_status, sara_schedule, district_name) %>%
summarise(og_species_area = sum(og_species_area)) %>%
ungroup()
og_ch_prot <- prot_ch_by_district%>%
mutate(og_prot_species_area=st_area(.),
og_prot_species_area =as.numeric(set_units(og_prot_species_area, ha))) %>%
st_set_geometry(NULL) %>%
rename_all(tolower) %>%
group_by(scientific_name, common_name_english, cosewic_status, schedule_status, sara_schedule, district_name) %>%
summarise(og_prot_species_area = sum(og_prot_species_area))
og_ch_faib <- faib_og_ch%>%
mutate(og_faib_species_area=st_area(.),
og_faib_species_area =as.numeric(set_units(og_faib_species_area, ha))) %>%
st_set_geometry(NULL) %>%
rename_all(tolower) %>%
group_by(scientific_name, common_name_english, cosewic_status, schedule_status, sara_schedule, district_name) %>%
summarise(og_faib_species_area = sum(og_faib_species_area))
output2<-ch_by_district %>%
mutate(species_area=st_area(.),
species_area =as.numeric(set_units(species_area, ha)),
species_area = replace_na(species_area,0)) %>%
st_set_geometry(NULL) %>%
rename_all(tolower) %>%
group_by(scientific_name, common_name_english, cosewic_status, schedule_status, sara_schedule, district_name) %>%
summarise(species_area = sum(species_area)) %>%
left_join(og_ch, by=c("scientific_name", "common_name_english", "cosewic_status",
"schedule_status", "sara_schedule", "district_name")) %>%
left_join(og_ch_prot, by=c("scientific_name", "common_name_english", "cosewic_status",
"schedule_status", "sara_schedule", "district_name")) %>%
left_join(og_ch_faib, by=c("scientific_name", "common_name_english", "cosewic_status",
"schedule_status", "sara_schedule", "district_name")) %>%
left_join(nat_res_area, by = "district_name") %>%
mutate_if(is.numeric, ~replace(., is.na(.),0)) %>%
mutate(og_ch_perc = og_species_area/species_area*100,
prot_ch_perc = og_prot_species_area/og_species_area *100,
unprotected_area = og_species_area - og_prot_species_area,
ch_at_risk_perc = og_faib_species_area/og_species_area *100,
ch_unprot_perc = unprotected_area/og_species_area *100,
og_ch_index = ch_at_risk_perc/og_ch_perc
)
write_csv(output2, "ch_species_summary_by_resource-district.csv")
summary_district_all <- output2 %>%
group_by(district_name) %>%
summarise(all_species_area = sum(species_area),
all_og_species_area = sum(og_species_area),
all_species_prot_area = sum(og_prot_species_area),
all_species_unprot_area = all_og_species_area - all_species_prot_area,
all_at_risk_species_area = sum(og_faib_species_area)) %>%
mutate(og_dist_perc = all_og_species_area/all_species_area*100,
prot_dist_perc = all_species_prot_area/all_og_species_area*100,
at_risk_dist_perc = all_at_risk_species_area/all_og_species_area*100,
og_index_dist = at_risk_dist_perc/og_dist_perc)
write_csv(summary_district_all, "ch_by_district_all.csv")
og_scientific_name <- c("Marmota vancouverensis", "Limnanthes macounii",
"Aegolius acadicus brooksi", "Cephalanthera austiniae",
"Hemphillia dromedarius", "Prophysaon coeruleum",
"Sphyrapicus thyroideus nataliae", "Brachyramphus marmoratus",
"Collema coniophilum", "Melanerpes lewis", "Rangifer tarandus",
"Accipiter gentilis laingi"
)
summary_district_og_dependent <- output2 %>%
filter(scientific_name %in% og_scientific_name) %>%
group_by(district_name) %>%
summarise(dep_species_area = sum(species_area),
dep_og_species_area = sum(og_species_area),
dep_species_prot_area = sum(og_prot_species_area),
dep_species_unprot_area = dep_og_species_area-dep_species_prot_area,
dep_at_risk_species_area = sum(og_faib_species_area)) %>%
mutate(dep_og_dist_perc = dep_og_species_area/dep_species_area*100,
dep_prot_dist_perc = dep_species_prot_area/dep_og_species_area*100,
dep_unprot_dist_perc = dep_species_unprot_area/dep_og_species_area*100,
dep_at_risk_dist_perc = dep_at_risk_species_area/dep_og_species_area*100,
dep_og_index_dist = dep_at_risk_dist_perc/dep_og_dist_perc)
write_csv(summary_district_og_dependent, "ch_by_district_og_dependent.csv")