Code
# Load packages
library(tidyverse)
library(viridisLite)
library(khroma)
library(sf)
library(mapview)
library(DT)
library(here)
library(conflicted)
# Declare package conflict preferences
conflicts_prefer(dplyr::filter())Dave Bosworth
December 9, 2025
# Import continuous WQ station coordinates
sf_stations <- read_sf(here("data/processed/spatial/cont_wq_stations.shp"))
# Import continuous WQ station metadata
df_metadata <- readRDS(here("data/processed/wq/cont_wq_metadata.rds"))
# Add metadata to station coordinates
sf_stations_c1 <- sf_stations %>%
left_join(df_metadata, by = join_by(Source, Station_ID)) %>%
relocate(Station_Name, .after = Station_ID) %>%
mutate(across(where(is.POSIXct), \(x) format(x, "%Y-%m-%d")))
# Import regions shapefile
sf_regions <- read_sf(here("data/processed/spatial/delta_regions.shp"))
# Create color palettes for station points (using Source) and region polygons
pal_stations <- plasma(n = length(unique(sf_stations_c1$Source)))
pal_regions <- color("muted")(length(unique(sf_regions$Region)))ndf_maps <- sf_stations_c1 %>%
nest(sf_data = everything(), .by = Parameter) %>%
arrange(Parameter) %>%
mutate(
maps = map(
sf_data,
\(x) {
mapview(
x,
zcol = "Source",
col.regions = pal_stations,
label = "Station_Name",
layer.name = "Source",
cex = 5
) +
mapview(
sf_regions,
zcol = "Region",
col.regions = pal_regions,
layer.name = "Region",
alpha.regions = 0.4
)
}
)
)---
title: "Continuous Water Quality Station Maps"
author: "Dave Bosworth"
date: today
date-format: long
format:
html:
code-fold: true
code-tools: true
execute:
message: false
warning: false
---
```{r}
# Load packages
library(tidyverse)
library(viridisLite)
library(khroma)
library(sf)
library(mapview)
library(DT)
library(here)
library(conflicted)
# Declare package conflict preferences
conflicts_prefer(dplyr::filter())
```
# Import and Prepare Data
```{r}
# Import continuous WQ station coordinates
sf_stations <- read_sf(here("data/processed/spatial/cont_wq_stations.shp"))
# Import continuous WQ station metadata
df_metadata <- readRDS(here("data/processed/wq/cont_wq_metadata.rds"))
# Add metadata to station coordinates
sf_stations_c1 <- sf_stations %>%
left_join(df_metadata, by = join_by(Source, Station_ID)) %>%
relocate(Station_Name, .after = Station_ID) %>%
mutate(across(where(is.POSIXct), \(x) format(x, "%Y-%m-%d")))
# Import regions shapefile
sf_regions <- read_sf(here("data/processed/spatial/delta_regions.shp"))
# Create color palettes for station points (using Source) and region polygons
pal_stations <- plasma(n = length(unique(sf_stations_c1$Source)))
pal_regions <- color("muted")(length(unique(sf_regions$Region)))
```
# Interactive Maps
```{r}
ndf_maps <- sf_stations_c1 %>%
nest(sf_data = everything(), .by = Parameter) %>%
arrange(Parameter) %>%
mutate(
maps = map(
sf_data,
\(x) {
mapview(
x,
zcol = "Source",
col.regions = pal_stations,
label = "Station_Name",
layer.name = "Source",
cex = 5
) +
mapview(
sf_regions,
zcol = "Region",
col.regions = pal_regions,
layer.name = "Region",
alpha.regions = 0.4
)
}
)
)
```
::: {.panel-tabset}
## `r ndf_maps$Parameter[1]`
```{r}
#| echo: false
ndf_maps$maps[[1]]
```
## `r ndf_maps$Parameter[2]`
```{r}
#| echo: false
ndf_maps$maps[[2]]
```
## `r ndf_maps$Parameter[3]`
```{r}
#| echo: false
ndf_maps$maps[[3]]
```
## `r ndf_maps$Parameter[4]`
```{r}
#| echo: false
ndf_maps$maps[[4]]
```
## `r ndf_maps$Parameter[5]`
```{r}
#| echo: false
ndf_maps$maps[[5]]
```
## `r ndf_maps$Parameter[6]`
```{r}
#| echo: false
ndf_maps$maps[[6]]
```
## `r ndf_maps$Parameter[7]`
```{r}
#| echo: false
ndf_maps$maps[[7]]
```
:::
# Station Metadata
```{r}
sf_stations_c1 %>%
st_drop_geometry() %>%
select(-c(Station_ID, SubRegion, CDEC_ID)) %>%
mutate(
across(c(Start, End), ymd),
across(c(Source, Region, Parameter, Interval), factor)
) %>%
datatable(filter = "top")
```