owned this note
owned this note
Published
Linked with GitHub
# INBO CODING CLUB
24 February 2025
Welcome!
## Share your code snippet
If you want to share your code snippet, copy paste your snippet within a section of three backticks (```):
As an **example**:
```
library(tidyverse)
```
(*you can copy paste this example and add your code further down*)
## Yellow sticky notes
No yellow sticky notes online. Put your name + " | " and add a "*" each time you solve a challenge (see below).
## Participants
Name | Challenges
--- | ---
Damiano Oldoni | ***
Dirk Maes |
Jorre |
Anja Leyman | ***
Rhea Maesele | **
Hans Van Calster |
Ward Langeraert |**
Margot Vanhellemont | **
Oberon Geunens|
Fleur Petersen |
Raïsa Carmen | **
Pieter Verschelde | **
Falk Mielke | **
Bryce |
Arno Thomaes | **
## Challenge 1
### Damiano's solution (example)
Copy paste this section to show your solutions.
```r
# dummy code
print("This is how to insert code.")
```
### Falk's attempt
(This is the whole `.Rmd` file.)
Based on the flexdashboard RMarkdown draft:
```
rmarkdown::draft("challenge1.Rmd",
template = "flex_dashboard_bslib",
package = "flexdashboard")
```
Code blocks copied from Damiano's `src` preparation.
````rmd
---
title: "CrayWatch Dashboard"
output:
flexdashboard::flex_dashboard:
vertical_layout: scroll
theme:
version: 4
fg: "#101010"
bg: "#FDF7F7"
primary: "#ED79F9"
navbar-bg: "#3ADAC6"
---
```{r setup, include=FALSE}
# Load libraries:
library(tidyverse) # to do datascience
library(here) # to work easily with paths
library(sf) # to work with geospatial vector data
library(leaflet) # to make dynamic maps
library(DT) # to make interactive tables
library(flexdashboard) # to make dashboards
# Install thematic and un-comment for themed static plots (i.e., ggplot2)
thematic::thematic_rmd()
```
```{r load-data, include=FALSE}
# Read data
# WARNING: my local data is organized differently; adjust the path.
cray_df <- readr::read_tsv(
here::here("codingclub", "data", "20250224_craywatch_cleaned.txt"),
na = "",
guess_max = 10000
)
glimpse(cray_df)
```
Column {}
-----------------------------------------------------------------------
### Species Abundance
```{r}
n_obs_per_month_species <-
cray_df %>%
count(year, month, species) %>%
# combine year and month to a single date
mutate(date = as.Date(paste0(year, "-", month, "-01"))) %>%
arrange(date, species) %>%
relocate(date,species, n, everything())
ggplot(n_obs_per_month_species,
aes(x = date, y = n, fill = species)) +
geom_bar(stat = 'identity') +
# Use inferno colors for the species
scale_fill_viridis_d(option = "inferno") +
# Add title and labels
ggtitle("Number of observations per month and species") +
xlab("Date") + ylab("Number of observations")
```
### Species Distribution
```{r}
## Chart 2 - bottom - Leaflet map ####
cray_fl <- sf::st_as_sf(cray_df,
coords = c("decimalLongitude", "decimalLatitude"),
crs = 4326)
# Create a palette that maps species to colors
pal <- colorFactor("inferno", cray_fl$species)
leaflet(cray_fl) %>%
addTiles() %>%
addCircleMarkers(popup = ~paste0(cray_fl$eventDate, ": ", cray_fl$species),
color = pal(cray_fl$species),
stroke = FALSE,
fillOpacity = 0.5,
radius = 4) %>%
addLegend(pal = pal, values = ~species,
position = "bottomright")
```
````
There are **quarto dashboards!**
https://quarto.org/docs/dashboards
````qmd
---
title: "CrayWatch Dashboard"
format:
dashboard:
theme: united
---
<!--
themes: https://quarto.org/docs/dashboards/theming.html
-->
```{r setup}
#| include: false
# Load libraries:
library(tidyverse) # to do datascience
library(here) # to work easily with paths
library(sf) # to work with geospatial vector data
library(leaflet) # to make dynamic maps
library(DT) # to make interactive tables
library(flexdashboard) # to make dashboards
# Install thematic and un-comment for themed static plots (i.e., ggplot2)
# thematic::thematic_qmd()
```
```{r load-data}
#| include: false
# Read data
cray_df <- readr::read_tsv(
here::here("codingclub", "data", "20250224_craywatch_cleaned.txt"),
na = "",
guess_max = 10000
)
glimpse(cray_df)
```
## Row {height=60%}
```{r}
n_obs_per_month_species <-
cray_df %>%
count(year, month, species) %>%
# combine year and month to a single date
mutate(date = as.Date(paste0(year, "-", month, "-01"))) %>%
arrange(date, species) %>%
relocate(date,species, n, everything())
ggplot(n_obs_per_month_species,
aes(x = date, y = n, fill = species)) +
geom_bar(stat = 'identity') +
# Use inferno colors for the species
scale_fill_viridis_d(option = "inferno") +
# Add title and labels
ggtitle("Number of observations per month and species") +
xlab("Date") + ylab("Number of observations")
```
## Row {height=40%}
```{r}
## Chart 2 - bottom - Leaflet map ####
cray_fl <- sf::st_as_sf(cray_df,
coords = c("decimalLongitude", "decimalLatitude"),
crs = 4326)
# Create a palette that maps species to colors
pal <- colorFactor("inferno", cray_fl$species)
leaflet(cray_fl) %>%
addTiles() %>%
addCircleMarkers(popup = ~paste0(cray_fl$eventDate, ": ", cray_fl$species),
color = pal(cray_fl$species),
stroke = FALSE,
fillOpacity = 0.5,
radius = 4) %>%
addLegend(pal = pal, values = ~species,
position = "bottomright")
```
````
### Ward's attempt
````Rmd
---
title: "Craywatch dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
# Load libraries:
library(tidyverse) # to do datascience
library(here) # to work easily with paths
library(sf) # to work with geospatial vector data
library(leaflet) # to make dynamic maps
library(DT) # to make interactive tables
library(flexdashboard) # to make dashboards
# Read data
cray_df <- readr::read_tsv(
here::here("data", "20250224", "20250224_craywatch_cleaned.txt"),
na = "",
guess_max = 10000
)
```
### Number of observations
```{r}
n_obs_per_month_species <-
cray_df %>%
count(year, month, species) %>%
# combine year and month to a single date
mutate(date = as_date(paste0(year, "-", month, "-01"))) %>%
arrange(date, species) %>%
relocate(date, species, n, everything())
ggplot(n_obs_per_month_species,
aes(x = date, y = n, fill = species)) +
geom_bar(stat = "identity") +
# Use inferno colors for the species
scale_fill_viridis_d(option = "inferno") +
# Add title and labels
labs(title = "Number of observations per month and species",
x = "", y = "Number of observations") +
scale_x_date(breaks = n_obs_per_month_species$date, date_labels = "%b") +
theme_minimal()
```
### Observations of Crayfish species
```{r}
cray_fl <- sf::st_as_sf(cray_df,
coords = c("decimalLongitude", "decimalLatitude"),
crs = 4326)
# Create a palette that maps species to colors
pal <- colorFactor("inferno", cray_fl$species)
leaflet(cray_fl) %>%
addTiles() %>%
addCircleMarkers(popup = ~paste0(cray_fl$eventDate, ": ", cray_fl$species),
color = pal(cray_fl$species),
stroke = FALSE,
fillOpacity = 0.5,
radius = 4) %>%
addLegend(pal = pal, values = ~species,
position = "bottomright")
```
````
## Challenge 2
### Poging Anja
````rmd
---
title: "Multiple pages"
output:
flexdashboard::flex_dashboard:
theme:
bg: "#101010"
fg: "#FDF7F7"
primary: "#ED79F9"
base_font:
google: Prompt
code_font:
google: JetBrains Mono
orientation: rows
vertical_layout: scroll
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse) # to do datascience
library(here) # to work easily with paths
library(sf) # to work with geospatial vector data
library(leaflet) # to make dynamic maps
library(DT) # to make interactive tables
library(flexdashboard) # to make dashboards
```
```{r load_data, include=FALSE}
# include=FALSE: code wordt gerund maar niet getoond
cray_df <- readr::read_tsv(
here::here("data", "20250224", "20250224_craywatch_cleaned.txt"),
na = "",
guess_max = 10000
)
glimpse(cray_df)
```
```{r }
# Number of observations linked to craywatch (via waarnemingen.be)
dataset_name <- "Waarnemingen.be - Non-native animal occurrences in Flanders and the Brussels Capital Region, Belgium"
n_obs_craywatch <- cray_df %>%
filter(datasetName == dataset_name) %>%
nrow()
tot_obs <- nrow(cray_df)
percentage_craywatch <- n_obs_craywatch / tot_obs * 100
```
SVZ
=====================================
Row
---
###
<!-- 1. A gauge on top to show in percentage the number of observations linked to craywatch (= obs from waarnemingen.be dataset). In this way, we show how impactful citizen science is for detecting these species. Tip: check the gauges section in the flexdashboard documentation. -->
```{r gauge}
# Number of observations linked to craywatch (via waarnemingen.be)
dataset_name <- "Waarnemingen.be - Non-native animal occurrences in Flanders and the Brussels Capital Region, Belgium"
n_obs_craywatch <- cray_df %>%
filter(datasetName == dataset_name) %>%
nrow()
tot_obs <- nrow(cray_df)
percentage_craywatch <- n_obs_craywatch / tot_obs * 100
gauge(percentage_craywatch, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(80, 100), warning = c(40, 79), danger = c(0, 39)
))
```
###
<!-- A value box with the absolute number of observations linked to craywatch (waarnemingen.be). Use a camera as icon. Tip: check the value boxes section in the flexdashboard documentation. And if you find a way to combine the gauge and the value box next to each other, please, shout it out loudly 📢 -->
```{r valuebox}
valueBox(tot_obs, icon = "fa-camera")
```
Row
-----------------------------------------------------------------------
<!-- At the bottom, a histogram with the number of observations per dataset. -->
### Number of observations per dataset
```{r histo}
n_obs_per_dataset <-
cray_df %>%
count(datasetName)
ggplot(n_obs_per_dataset,
aes(x = datasetName, y = n, fill = datasetName)) +
geom_bar(stat = 'identity') +
geom_text(aes(label = n), vjust = 0, hjust = 0) +
scale_x_discrete(label = function(x) stringr::str_trunc(x, 30)) + # met dank aan Ward
scale_y_continuous(limits = c(0, 1300)) +
# Add title and labels
# ggtitle("Number of observations per dataset") +
labs(x = "", y = "Number of observations") +
coord_flip() +
theme(legend.position = "none")
```
Waarnemingen per maand
=====================================
Row
-------------------------------------
### Number of observations
```{r histo}
n_obs_per_month_species <-
cray_df %>%
count(year, month, species) %>%
# combine year and month to a single date
mutate(date = as.Date(paste0(year, "-", month, "-01"))) %>%
arrange(date, species) %>%
relocate(date,species, n, everything())
ggplot(n_obs_per_month_species,
aes(x = date, y = n, fill = species)) +
geom_bar(stat = 'identity') +
# Use inferno colors for the species
scale_fill_viridis_d(option = "inferno") +
# Add title and labels
ggtitle("Number of observations per month and species") +
xlab("Date") + ylab("Number of observations")
```
Row
-----------------------------------------------------------------------
### Map
```{r}
## Chart 2 - bottom - Leaflet map ####
cray_fl <- sf::st_as_sf(cray_df,
coords = c("decimalLongitude", "decimalLatitude"),
crs = 4326)
# Create a palette that maps species to colors
pal <- colorFactor("inferno", cray_fl$species)
leaflet(cray_fl) %>%
addTiles() %>%
addCircleMarkers(popup = ~paste0(cray_fl$eventDate, ": ", cray_fl$species),
color = pal(cray_fl$species),
stroke = FALSE,
fillOpacity = 0.5,
radius = 4) %>%
addLegend(pal = pal, values = ~species,
position = "bottomright")
```
````qmd
````
### Ward's Attempt
````Rmd
---
title: "Craywatch dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
# Load libraries:
library(tidyverse) # to do datascience
library(here) # to work easily with paths
library(sf) # to work with geospatial vector data
library(leaflet) # to make dynamic maps
library(DT) # to make interactive tables
library(flexdashboard) # to make dashboards
# Read data
cray_df <- readr::read_tsv(
here::here("data", "20250224", "20250224_craywatch_cleaned.txt"),
na = "",
guess_max = 10000
)
```
Crayfish distribution
=====================================
### Number of observations
```{r}
n_obs_per_month_species <-
cray_df %>%
count(year, month, species) %>%
# combine year and month to a single date
mutate(date = as_date(paste0(year, "-", month, "-01"))) %>%
arrange(date, species) %>%
relocate(date, species, n, everything())
ggplot(n_obs_per_month_species,
aes(x = date, y = n, fill = species)) +
geom_bar(stat = "identity") +
# Use inferno colors for the species
scale_fill_viridis_d(option = "inferno") +
# Add title and labels
labs(title = "Number of observations per month and species",
x = "", y = "Number of observations") +
scale_x_date(breaks = n_obs_per_month_species$date, date_labels = "%b") +
theme_minimal()
```
### Observations of Crayfish species
```{r}
cray_fl <- sf::st_as_sf(cray_df,
coords = c("decimalLongitude", "decimalLatitude"),
crs = 4326)
# Create a palette that maps species to colors
pal <- colorFactor("inferno", cray_fl$species)
leaflet(cray_fl) %>%
addTiles() %>%
addCircleMarkers(popup = ~paste0(cray_fl$eventDate, ": ", cray_fl$species),
color = pal(cray_fl$species),
stroke = FALSE,
fillOpacity = 0.5,
radius = 4) %>%
addLegend(pal = pal, values = ~species,
position = "bottomright")
```
Citizen science {data-orientation=rows}
=====================================
Row
-------------------------------------
### Citizen science data for detecting crayfish
```{r}
dataset_name <- paste("Waarnemingen.be - Non-native animal occurrences in",
"Flanders and the Brussels Capital Region, Belgium")
n_obs_craywatch <- cray_df %>%
filter(datasetName == dataset_name) %>%
nrow()
tot_obs <- nrow(cray_df)
percentage_craywatch <- n_obs_craywatch / tot_obs * 100
gauge(percentage_craywatch, min = 0, max = 100, symbol = "%",
gaugeSectors(success = c(80, 100), warning = c(40, 79), danger = c(0, 39))
)
```
### Articles per Day
```{r}
valueBox(tot_obs, caption = "Number of observations linked to craywatch",
icon = "ion-android-cloud-done")
```
Row
-------------------------------------
### Number of observations per dataset
```{r}
cray_df %>%
count(datasetName) %>%
mutate(datasetName = reorder(datasetName, n)) %>%
ggplot(aes(x = datasetName, y = n)) +
geom_bar(stat = "identity",
fill = "cornflowerblue") +
geom_text(aes(label = n), vjust = 0, hjust = 0) +
scale_x_discrete(label = function(x) stringr::str_trunc(x, 30)) +
scale_y_continuous(limits = c(0, 1300)) +
labs(x = "", y = "Number of observations") +
theme_minimal() +
coord_flip()
```
````
### Falk's Quarto Attempt
````Qmd
---
title: "CrayWatch Dashboard"
format:
dashboard:
theme:
light: lux
dark: solar
logo: https://www.vlaanderen.be/inbo/images/INBO-logo.svg
scrolling: false
expandable: true
nav-buttons:
- icon: github
href: https://coding-club.inbo.be
---
<!--
themes: https://quarto.org/docs/dashboards/theming.html
-->
```{r setup}
#| include: false
# Load libraries:
library(tidyverse) # to do datascience
library(here) # to work easily with paths
library(sf) # to work with geospatial vector data
library(leaflet) # to make dynamic maps
library(DT) # to make interactive tables
library(flexdashboard) # to make dashboards
# Install thematic and un-comment for themed static plots (i.e., ggplot2)
# thematic::thematic_qmd() # thematic does not cooperate with quarto yet https://github.com/quarto-dev/quarto-cli/discussions/9331
```
```{r load-data}
#| include: false
# Read data
cray_df <- readr::read_tsv(
here::here("codingclub", "data", "20250224_craywatch_cleaned.txt"),
na = "",
guess_max = 10000
)
glimpse(cray_df)
```
# Overview
## Row {height=25%}
```{r calculate-rates}
#| include: false
dataset_name <- "Waarnemingen.be - Non-native animal occurrences in Flanders and the Brussels Capital Region, Belgium"
n_obs_craywatch <- cray_df %>%
filter(datasetName == dataset_name) %>%
nrow()
tot_obs <- nrow(cray_df)
percentage_craywatch <- n_obs_craywatch / tot_obs * 100
```
### Column {.flow}
```{r}
gauge(percentage_craywatch, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(0,50),
warning = c(50,80),
danger = c(80,100),
colors = c(success = "#bd4583", warning = "#bd4583", "danger" = "#bd4583")
))
```
### Column {.flow}
<!-- https://quarto.org/docs/dashboards/data-display.html -->
```{r}
#| content: valuebox
#| title: "total observations"
list(
icon = "camera",
color = "#dea3c3",
value = tot_obs
)
```
## Row {.flow}
```{r}
cray_df %>%
count(datasetName) %>%
mutate(datasetName = reorder(datasetName, n)) %>%
ggplot(aes(x = datasetName, y = n)) +
geom_bar(stat = "identity",
fill = "#bd4583", color = "black") +
geom_text(aes(label = n), vjust = 0, hjust = 0) +
scale_x_discrete(label = function(x) stringr::str_trunc(x, 30)) +
scale_y_continuous(limits = c(0, 1300)) +
labs(x = "", y = "Number of observations") +
theme_minimal() +
coord_flip()
```
# Details
## Row {height=40%, .tabset}
```{r}
#| title: Species Abundance
n_obs_per_month_species <-
cray_df %>%
count(year, month, species) %>%
# combine year and month to a single date
mutate(date = as.Date(paste0(year, "-", month, "-01"))) %>%
arrange(date, species) %>%
relocate(date,species, n, everything())
ggplot(n_obs_per_month_species,
aes(x = date, y = n, fill = species)) +
geom_bar(stat = 'identity') +
# Use inferno colors for the species
scale_fill_viridis_d(option = "inferno") +
# Add title and labels
ggtitle("Number of observations per month and species") +
xlab("Date") + ylab("Number of observations")
```
```{r}
#| title: Species Distribution
cray_fl <- sf::st_as_sf(cray_df,
coords = c("decimalLongitude", "decimalLatitude"),
crs = 4326)
# Create a palette that maps species to colors
pal <- colorFactor("inferno", cray_fl$species)
leaflet(cray_fl) %>%
addTiles() %>%
addCircleMarkers(popup = ~paste0(cray_fl$eventDate, ": ", cray_fl$species),
color = pal(cray_fl$species),
stroke = FALSE,
fillOpacity = 0.5,
radius = 4) %>%
addLegend(pal = pal, values = ~species,
position = "bottomright")
```
````
### Poging Rhea
````rmd
---
title: "Craywatch dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
---
```{r setup, include=FALSE}
# Load libraries:
library(tidyverse) # to do datascience
library(here) # to work easily with paths
library(sf) # to work with geospatial vector data
library(leaflet) # to make dynamic maps
library(DT) # to make interactive tables
library(flexdashboard) # to make dashboards
# Read data
cray_df <- readr::read_tsv(
here::here("data", "20250224", "20250224_craywatch_cleaned.txt"),
na = "",
guess_max = 10000
)
```
Citizen Science
=====================================
Column {data-width=650}
-----------------------------------------------------------------------
### Impact citizen science
```{r Gauge chart}
## Gauge chart and value box on top ####
# Number of observations linked to craywatch (via waarnemingen.be)
dataset_name <- "Waarnemingen.be - Non-native animal occurrences in Flanders and the Brussels Capital Region, Belgium"
n_obs_craywatch <- cray_df %>%
filter(datasetName == dataset_name) %>%
nrow()
tot_obs <- nrow(cray_df)
percentage_craywatch <- n_obs_craywatch / tot_obs * 100
gauge(percentage_craywatch, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(75, 100), warning = c(35, 74), danger = c(0, 34)
))
```
### Absolute number of observations linked to Craywatch (waarnemingen.be)
```{r value box}
## Gauge chart and value box on top ####
#Tip: Use camera as icon
# Number of observations linked to craywatch (via waarnemingen.be)
dataset_name <- "Waarnemingen.be - Non-native animal occurrences in Flanders and the Brussels Capital Region, Belgium"
n_obs_craywatch <- cray_df %>%
filter(datasetName == dataset_name) %>%
nrow()
tot_obs <- nrow(cray_df)
percentage_craywatch <- n_obs_craywatch / tot_obs * 100
valueBox(tot_obs, icon = "fa-camera")
```
Column {data-width=650}
-----------------------------------------------------------------------
### Number of observations per dataset
```{r}
#histogram with the number of observations per dataset
short_names <- c("Waarnemingen.be - Non-native animal occurrences in Flanders and the Brussels Capital Region, Belgium" = "Waarnemingen.be",
"RATO - Daily operations commissioned by the province East Flanders, Belgium" = "RATO",
"Invasive species - American bullfrog (Lithobates catesbeianus) in Flanders, Belgium (post 2018)" = "IS - American bullfrog",
"iNaturalist research-grade observations" = "iNaturalist",
"Monitoring of fishes and crustaceans by Province East Flanders in Flanders, Belgium" = "Monitoring Province EF")
cray_df %>%
group_by(datasetName) %>%
summarise(tot_obs_dataset = n()) %>%
mutate(short_name = short_names[datasetName]) %>%
ggplot() +
geom_bar(aes(x = short_name, y = tot_obs_dataset), stat = 'identity') +
labs(title = "Aantal observaties per dataset",
x = "Dataset",
y = "Aantal observaties") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
Crayfishes in Flanders {data-orientation=rows}
=====================================
Column {data-width=350}
-----------------------------------------------------------------------
### Plot per date (year/month) and species
```{r Chart 1}
## Chart 1 - top - Plot per date (year/month) and species ####
n_obs_per_month_species <-
cray_df %>%
count(year, month, species) %>%
# combine year and month to a single date
mutate(date = as.Date(paste0(year, "-", month, "-01"))) %>%
arrange(date, species) %>%
relocate(date,species, n, everything())
ggplot(n_obs_per_month_species,
aes(x = date, y = n, fill = species)) +
geom_bar(stat = 'identity') +
# Use inferno colors for the species
scale_fill_viridis_d(option = "inferno") +
# Add title and labels
ggtitle("Number of observations per month and species") +
xlab("Date") + ylab("Number of observations")
```
Column {data-width=350}
-----------------------------------------------------------------------
### Leaflet map
```{r Chart 2}
## Chart 2 - bottom - Leaflet map ####
cray_fl <- sf::st_as_sf(cray_df,
coords = c("decimalLongitude", "decimalLatitude"),
crs = 4326)
# Create a palette that maps species to colors
pal <- colorFactor("inferno", cray_fl$species)
leaflet(cray_fl) %>%
addTiles() %>%
addCircleMarkers(popup = ~paste0(cray_fl$eventDate, ": ", cray_fl$species),
color = pal(cray_fl$species),
stroke = FALSE,
fillOpacity = 0.5,
radius = 4) %>%
addLegend(pal = pal, values = ~species,
position = "bottomright")
```
````
## Challenge 3
### Ward's attempt
https://rpubs.com/wlangera/1275856
RPubs dashboard be deleted after coding club.
yml header used:
```
---
title: "Craywatch dashboard"
output:
flexdashboard::flex_dashboard:
theme:
version: 4
bg: "#ffffff"
fg: "#356196"
primary: "#c04384"
navbar-bg: "#000000"
base_font:
Cailibri
heading_font:
Sans Pro
source_code: embed
orientation: columns
vertical_layout: fill
---
```
See screenshot example here:
