This document provides an interactive map of the sampling locations used in the trait-based special study for the Drought Synthesis.
# Load packages
library(tidyverse)
library(viridisLite)
library(sf)
library(mapview)
# Make sure we are using `deltamapr` version 1.0.0, commit 5b11044a14aada45562d92899e2d8db42c0e8daf
# install.packages("devtools")
# devtools::install_github("InteragencyEcologicalProgram/deltamapr", ref = "5b11044a14aada45562d92899e2d8db42c0e8daf")
library(deltamapr)
library(here)
library(conflicted)
# Declare package conflict preferences
conflicts_prefer(dplyr::filter())
# Check if we are in the correct working directory
i_am("Sample_Location_Map.Rmd")
# Set default options for mapview - turn off basemap color shuffle
mapviewOptions(basemaps.color.shuffle = FALSE)
# Function to create custom individual mapview objects for a set of coordinates
mapview_from_coord <- function(sf, layer_name, pt_color) {
mapview(
sf,
layer.name = layer_name,
col.regions = pt_color,
alpha.regions = 0.8,
cex = 5,
label = "Station"
)
}
# Import station coordinates for biological data
df_bio_coord <- read_csv(here("Station_coordinates.csv"))
# Import region polygon used for filtering spatial extent of biological data
sf_region <- read_sf(here("spatial_files/region.shp"))
# Load Delta subregion polygons from the Drought Synthesis
sf_delta <- R_EDSM_Subregions_Mahardja_FLOAT %>%
select(SubRegion) %>%
# Remove a few subregions outside our area of interest
filter(!SubRegion %in% c("San Francisco Bay", "South Bay", "Upper Napa River"))
# Prepare station coordinates of biological data for map - separate by taxon so
# they can be added as independent layers
ndf_bio_coord <- df_bio_coord %>%
rename_with(str_to_title) %>%
drop_na(Lat_wgs84, Long_wgs84) %>%
st_as_sf(coords = c("Long_wgs84", "Lat_wgs84"), crs = 4326) %>%
# Convert CRS so that its the same as the region and subregion polygons
st_transform(crs = st_crs(sf_delta)) %>%
nest(.by = Taxon, .key = "sf_coord") %>%
mutate(Taxon = str_to_title(Taxon)) %>%
arrange(Taxon)
# Create list of two mapview layers of the region and subregion polygons to be
# used in the map
ls_map_polygons <- list(
mapview(
sf_region,
alpha.regions = 0,
color = "blue",
lwd = 2,
legend = FALSE,
layer.name = "Region boundary"
),
mapview(
sf_delta,
alpha.regions = 0.4,
legend = FALSE,
layer.name = "Delta subregions"
)
)
This interactive map allows for zooming and panning. Hover over or click a station marker to get more information about it. The layers button on the top left allows for toggling individual layers on and off. The blue polygon represents the region boundary we are considering for the spatial extent of the study, and the polygons within it represent subregions used in the Drought Synthesis.
# Create map using mapview
ndf_bio_coord %>%
mutate(
point_color = plasma(n = 4),
map_obj = pmap(list(sf_coord, Taxon, point_color), mapview_from_coord)
) %>%
pull(map_obj) %>%
append(ls_map_polygons) %>%
reduce(`+`)