-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_load.R
82 lines (55 loc) · 2.91 KB
/
01_load.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
# Copyright 2019 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
# Loading R libraries ---------------------------------------------------
Packages <- c("sf", "tidyverse", "maptools", "devtools","bcmaps",
"leaflet", "rmapshaper", "envreportutils",
"viridis", "here", "readxl","bcdata", "units",
"svglite", "Cairo", "shiny", "htmltools")
lapply(Packages, library, character.only = TRUE)
#remotes::install_github("ateucher/rmapshaper")
#remotes::install_github("bcgov/bcdata")
#remotes::install_github("bcgov/envreportutils")
#devtools::install_github("dkahle/ggmap", force = T)
#remotes::install_github("bcgov/bcmaps")
## Data Download -------------------------------------------------------
## Get British Columbia grizzly bear data from B.C. Data Catalogue
## Data is released under the Open Government Licence - British Columbia
# 1) Import conservation ranking table:
# https://catalogue.data.gov.bc.ca/dataset/e08876a1-3f9c-46bf-b69a-3d88de1da725
threat_calc <- bcdc_get_data(record = 'e08876a1-3f9c-46bf-b69a-3d88de1da725',
resource = '7282667b-185a-4f08-9d99-13a2e5ada1d4') %>%
rename_all(tolower) %>%
rename(gbpu_name = gbpu,
gbpu.pop = popnest2018,
threat_class = overal_threat)
# 2) Import grizzly bear population unite (gbpu) spatial data
gbpu_poly_raw <- bcdc_get_data("https://catalogue.data.gov.bc.ca/dataset/caa22f7a-87df-4f31-89e0-d5295ec5c725")
gbpu_poly <- gbpu_poly_raw %>%
filter(VERSION_NAME == 2018) %>%
select(-c(id, VERSION_NAME, VERSION_YEAR_MODIFIED,
SE_ANNO_CAD_DATA, FEATURE_LENGTH_M,
WITHIN_BC_IND)) %>%
mutate(gbpu_name = POPULATION_NAME)
names(gbpu_poly) <- tolower(names(gbpu_poly))
# 3) Import population data from data catalogue
pop.raw <- bcdc_get_data("https://catalogue.data.gov.bc.ca/dataset/2bf91935-9158-4f77-9c2c-4310480e6c29",
resource = '6406840f-9525-4544-9c36-e725fb2e399a')
pop <- pop.raw %>%
rename_all(tolower) %>%
rename(population_name = population_name,
pop_est = gbpu_est_pop_2018,
pop_area = gbpu_area_km2_nowaterice) %>%
select(c(population_name, pop_area, pop_est))
gbpu_data <- left_join(gbpu_poly, pop, by = "population_name")
# 4. Import mortality data set
# (https://catalogue.data.gov.bc.ca/dataset/history-of-grizzly-bear-mortalities)
morts <- bcdc_get_data("4bc13aa2-80c9-441b-8f46-0b9574109b93")