-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_map.R
64 lines (52 loc) · 2.3 KB
/
make_map.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
## NICOLAS' previous code (thanks nico!!)
# plot_sf <- readRDS(here::here("data", "plot_coords.rds"))
#
# m <- mapview::mapview(plot_sf, zcol = "projectTitle")
# mapview::mapshot(m, url = here::here("index.html"))
# Load other required libraries
# install.packages("webshot")
# library(webshot)
# webshot::install_phantomjs()
# library(mapview)
# library(here)
## RENATO'S adapted code
# getting the most up-to-date plot data
path.from <- gsub("plotmap", "WP1_Data_harmonization/data/derived-data/database",
here::here())
list.files(path.from) # chose the most up-to-date version and change below
version.name <- "syntreesys_dataset_version_0.0.6.rds"
path.from1 <- file.path(path.from, version.name)
path.to <- here::here(list("data", version.name))
file.copy(from = path.from1, to = path.to, overwrite = TRUE, recursive = FALSE)
# loading the data and getting the sf object
plots <- readRDS(here::here("data", version.name))$Plots
plots <- plots[!is.na(plots$plotLatitude), ]
plots$network <- ifelse(
plots$country == "Colombia" & grepl("Red BST-Col", plots$citationString),
"RedBST-Col",
plots$network
)
projcrs <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
plots_sf <- sf::st_as_sf(x = plots[, c("plotLongitude", "plotLatitude", "network")],
coords = c("plotLongitude", "plotLatitude"),
crs = projcrs)
rep_these <- plots_sf$network %in% c("GuatemalaPlots", "ManabiPlots",
"MisionesPlots", "SanEmilio",
"Botropandes")
plots_sf$network[rep_these] <- "Miscellaneous"
library(RColorBrewer)
# Define color palette function using RColorBrewer (Set3 for high contrast)
# preparing and rendering the map
col.f <- function (n) { brewer.pal((n), "Set3") }
m <- mapview::mapview(plots_sf, zcol = "network",
col.regions = col.f,
#native.crs = TRUE,
map.types = c(
#"CartoDB.Positron",
#"CartoDB.DarkMatter"
"OpenStreetMap",
"Esri.WorldImagery",
"OpenTopoMap"),
layer.name = "SynTreeSys networks"
)
mapview::mapshot(m, url = here::here("index.html"))