owned this note
owned this note
Published
Linked with GitHub
# INBO CODING CLUB
21 March 2019
Welcome!
## A few more resources
- Overview Belgian WMS services: https://wms.michelstuyts.be/
- Book 'Geocomputing with R': https://geocompr.robinlovelace.net/
- [Notes and material from the tutorial](https://drive.google.com/drive/folders/0B-DYcTNHFnIXeUhfOFYtZEw4LUU?usp=sharing) on geospatial data visualization on the useR!2017 conference.
## 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**:
```r
library(tidyverse)
...
```
(*you can copy paste this example and add your code further down, but do not fill in your code in this section*)
*Your snippets:*
## Challenge 1
There is no data for Limburg in 2016. You can add it to still have it in the map.
First option: use `spread` and `gather`
```r
n_crab_provinces <- n_crab_provinces %>%
spread(year, n) %>%
gather(key = "year", value = "n", `2015`, `2016`)
```
Second option by adding a new row:
```r
n_crab_provinces_2016_limburg <-
n_crab_provinces %>%
filter(TX_PROV_DESCR_NL == "Provincie Limburg") %>%
mutate(year = 2016, n = NA_integer_)
n_crab_provinces <-
n_crab_provinces %>%
bind_rows(n_crab_provinces_2016_limburg)
```
### Poging Britt
```r
provincecrabs <- left_join(
provinces, n_crab_provinces,
by = c('CD_PROV_REFNIS' = 'CD_PROV_REFNIS'))
provincecrabs2016 <- filter(provincecrabs, year == 2016)
ggplot(provincecrabs2016) +
geom_sf(aes(fill = n))
```
### Toon
```r
n_crab_provinces_2016 <- n_crab_provinces %>%
rename(province = TX_PROV_DESCR_NL) %>%
group_by(province) %>%
summarise(n = sum(n * (year == 2016))) %>% #geeft een 0 voor Limburg
ungroup()
provinces_crab <- provinces %>%
rename(province = TX_PROV_DESCR_NL) %>%
left_join(n_crab_provinces_2016, by = "province")
provinces_crab %>%
ggplot(aes(fill = n)) +
geom_sf()
```
# Jeroen
```r
n_crab_2016 <- n_crab_provinces %>%
filter(year == 2016)
crab_prov <- left_join(provinces, n_crab_2016, by = "TX_PROV_DESCR_NL") %>%
mutate(n2016 = ifelse(is.na(n), 0, n))
ggplot(crab_prov) + geom_sf(aes(fill = n2016))
```
### Google resultaat om NA toe te voegen aan de legende - Ivy
```r
crab_2016 <- n_crab_provinces %>%
filter(year == 2016)
provinces_2016 <- provinces %>%
left_join(crab_2016, by = "TX_PROV_DESCR_NL") %>%
mutate(discrete_n = cut(.$n, breaks = seq(from = 20, to = 100, by = 10)))
ggplot(provinces_2016) +
geom_sf(aes(fill = discrete_n)) +
scale_fill_brewer(na.value = "black")
```
## Challenge 2
### Poging Britt (challenge )
```r
binpal <- colorBin("RdPu",
provincecrabs2016$n,
6,
pretty = TRUE)
m <- leaflet() %>%
addTiles() %>%
addPolygons(data = provincecrabs2016,
fillColor = ~binpal(n),
stroke = FALSE,
fillOpacity = 0.8) %>%
addLegend("bottomright",
pal = binpal,
values = provincecrabs2016$n,
title = "Number of mitten crabs per province (2016)",
opacity = 1
)
m
```
### Emma
```r
pal <- colorBin(palette = rev(heat.colors(11)), bins = c(1,10,20,30,40,50,60,70,80,90,100, +Inf),
na.color="#cecece")
map <- leaflet(n_crab_provinces2016) %>%
addTiles() %>%
addLegend(title = "Aantal krabben",
pal = pal, values = ~n,
position = "bottomleft") %>%
addPolygons(color = ~pal(n),
stroke = FALSE, smoothFactor = 0.2, fillOpacity = 0.85,
popup = sprintf("%s<br>%s",n_crab_provinces2016$TX_PROV_DESCR_NL,
n_crab_provinces2016$n)) %>%
addPolylines(weight = 1.5, color = "black")
print(map)
```
### Floris
```r
pal <- colorNumeric(
palette = "Blues",
domain = prov_crab$n)
prov_crab %>%
leaflet() %>%
addTiles() %>%
addPolygons(weight = 1,
smoothFactor = 0.2,
fillOpacity = 0.5,
color = ~pal(n))
```
# Challenge 3
### Britt (challenge 3)
```r
# VMM WMS is precies down, maar gebruik gerust de Scheldemonitorlayers van VLIZ :)
# "http://geo.vliz.be/geoserver/wms?&request=getcapabilities"
crabs2015_spatial <- st_as_sf(crab_df_2015,
coords = c("decimalLongitude","decimalLatitude"),
crs=4326)
m <- leaflet() %>%
setView(4.2813167,51.1373384,13) %>%
addTiles() %>%
addCircleMarkers(data = crabs2015_spatial,
color = 'green',
radius = 5,
stroke = FALSE,
fillOpacity = 0.5,
popup = crabs2015_spatial$eventDate,
popupOptions = popupOptions(maxWidth = 1000,
closeOnClick = TRUE)) %>%
addWMSTiles("http://geo.vliz.be/geoserver/wms",
layers = "Scheldemonitor:gebiedsindeling_om",
options = WMSTileOptions(format = "image/png", transparent = TRUE))
m
```
### Ivy (zonder WMS)
```r
crab_df_2015 <- read_csv("./data/20190321_crab_occurrences_2015.csv") %>%
st_as_sf(coords = c("decimalLongitude", "decimalLatitude"))
leaflet(crab_df_2015) %>%
addTiles() %>%
addCircles() %>%
addMarkers(label = ~as.character(eventDate)) %>%
setView(lng = 4.2813167, lat = 51.1373384, zoom = 12)
```
### floris
```r
crab_df_2015_xy <-
crab_df_2015 %>%
rename(X = decimalLongitude,
Y = decimalLatitude)
leaflet() %>%
addTiles() %>%
addPolygons(data = prov_crab,
weight = 1,
smoothFactor = 0.2,
fillOpacity = 0.5,
color = ~pal(n)) %>%
addMarkers(data = crab_df_2015_xy, ~X, ~Y) %>%
addPopups(data = crab_df_2015_xy, ~X, ~Y, popup = ~identifiedBy)
```