owned this note
owned this note
Published
Linked with GitHub
# INBO CODING CLUB
6 December 2022
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 | ***
Teun Everts |
Lynn Pallemaerts | ***
Heleen Deroo |
Ward Langeraert |
An Leyssen |
Wouter Depaepe|
Raïsa Carmen | ***
Oberon Geunens
Wim Mertens| *
Pieter Huybrechts | ***
## Challenge 1
Damiano:
```
a <- 1 #dummy example
```
Pieter:
```
## Natura 2000
natura2000 %>%
ggplot() +
geom_sf() +
aes(fill = Shape_area) +
scale_color_viridis_c(aesthetics = "fill")`
## Nitrogen
nitrogen %>%
terra::plot(range = c(10, 47),
col = hcl.colors(n = 100, palette = "Blue-Red 3"))
## Land Use
lu_nara_2016 %>%
terra::plot(
main = "Land Use of Flanders",
type = "classes",
plg = list(legend = c(legend_land_use$land_use)),
col = legend_land_use$color,
)
### Alternative :
lu_nara_2016 %>%
terra::plot(
main = "Land Use of Flanders",
type = "classes",
levels = legend_land_use$land_use,
col = legend_land_use$color
)
```
Lynn
```
ggplot(data = natura2000) +
geom_sf(aes(fill = Shape_area)) +
scale_fill_viridis_c()
clr <- hcl.colors(n = 100, palette = "Blue-Red 3")
plot(nitrogen, range = c(10, 47), col = clr)
plot(lu_nara_2016, legend = F, main = "Land use in Flanders", col = legend_land_use$color)
legend("top",
legend = legend_land_use$land_use,
fill = legend_land_use$color,
xjust = 1,
yjust = 1,
ncol = 3) # is een oplossing, maar is heel lelijk
```
Wim
```
ggplot(natura2000) +
geom_sf(aes(fill = Shape_area)) +
scale_fill_viridis_b()
plot(nitrogen,
range = c(10, 47),
col = hcl.colors(n = 100, palette = "Blue-Red 3")
)
plot(lu_nara_2016,
main = "Landgebruik Vlaanderen",
type = "classes",
col = legend_land_use$color,
levels = legend_land_use$land_use)
```
## Challenge 2
Lynn
```
fl_osm <- get_tiles(natura2000,
crop = TRUE) # download tiles and crop them to flanders
plot_tiles(fl_osm) # plot tiles
plot(natura2000,
col = natura2000$Shape_area,
add = TRUE) # plot flanders
mtext(text = get_credit("OpenStreetMap"),
side = 1,
line = -1,
adj = 1,
cex = .9,
font = 3) # add credit
```
Pieter:
```
### Part 1:
natura2000 %>%
get_tiles(provider = "CartoDB.Positron", crop = T,zoom = 9) %>%
plot_tiles()
terra::plot(st_geometry(natura2000), add = TRUE, col = sample(colours(),1))
mtext(text = get_credit("OpenStreetMap"),
side = 1, line = -1, adj = 1, cex = .9,
font = 3)
### part 2
selected_provider <- "CartoDB.Positron"
viridis_pallette <-
viridisLite::viridis(length(natura2000$Shape_area))
natura2000 %>%
get_tiles(provider = selected_provider, crop = T,zoom = 9) %>%
plot_tiles()
#### colours don't correspond to area's!
terra::plot(st_geometry(natura2000),
col = viridis_pallette,
type = "continous",
plg = list(legend = c(natura2000$Shape_area)),
add = TRUE)
mtext(text = get_credit(selected_provider),
side = 1, line = -1, adj = 1, cex = .9,
font = 3)
```
Ward:
```
# 1.
# Get tiles
natura2000_osm <- get_tiles(natura2000, crop = TRUE, zoom = 9)
# display map
plot_tiles(natura2000_osm, main = "Natura2000 gebieden", line = -2)
# add natura2000 areas
plot(st_geometry(natura2000), col = "cornflowerblue", add = TRUE)
# Add credits
mtext(text = get_credit("OpenStreetMap"),
side = 1, line = -1, adj = 1, cex = .9,
font = 3)
# 2.
# Get tiles
natura2000_osm2 <- get_tiles(natura2000, crop = TRUE, zoom = 9,
provider = "Esri.NatGeoWorldMap")
# display map
plot_tiles(natura2000_osm2, main = "Natura2000 gebieden", line = -2)
# Create colour palette
my.palette <- rgb(natura2000$Shape_area,
max(natura2000$Shape_area) - natura2000$Shape_area,
0, maxColorValue = max(natura2000$Shape_area))
# add natura2000 areas
plot(st_geometry(natura2000), col = my.palette, add = TRUE)
# how do I add legend?
# Add credits
mtext(text = get_credit("OpenStreetMap"),
side = 1, line = -1, adj = 1, cex = .9,
font = 3)
```
To save:
png('test.png')
natura_2000_osm <- get_tiles(natura2000)
plot_tiles(natura_2000_osm)
plot(st_geometry(natura2000), col = NA, add = TRUE)
mtext(text = get_credit("OpenStreetMap"),
side = 1, line = -1, adj = 1, cex = .9,
font = 3)
dev.off()
Luc
```
library(tidyterra)
ggplot() + geom_spatraster_rgb(data = fl_osm) +
geom_sf(data = natura2000, aes(fill = Shape_area)) +
scale_color_viridis_c(aesthetics = "fill") +
theme_map() + theme(legend.position = "right")
```
## Challenge 3
Lynn
```
mapviewOptions(basemaps = c("OpenStreetMap.DE"))
mapview(natura2000,
legend = T,
color = "red",
zcol = "n_occs",
alpha.regions = 0.9,
alpha = 0.2,
layer.name = "n obs") %>%
addLogo(img = img)
```
Pieter:
```
cc_img <- "https://raw.githubusercontent.com/inbo/coding-club/master/docs/assets/images/coding_club_logo.svg"
mapviewOptions(basemaps = "OpenStreetMap.Mapnik")
mapview::mapview(natura2000,
zcol = "n_occs",
color = "red",
alpha = 0.2,
alpha.regions = 0.9,
layer.name = "# hogweed observations") %>%
addLogo(img = cc_img)
```
Raïsa:
```
#Q1:
mapView(natura2000,
zcol = "n_occs",
color = "red")
#Q2:
map_hogweed <- mapView(natura2000,
zcol = "n_occs",
color = "red",
map.types = "OpenStreetMap",
layer.name = "n obs",
alpha.regions = 0.9,
lwd = 0.2,#line width
)
#Q3. link to image
img <- "https://raw.githubusercontent.com/inbo/coding-club/master/docs/assets/images/coding_club_logo.svg"
url <- "https://inbo.github.io/coding-club/"
addLogo(map = map_hogweed,
img = img,
url = url)
```
Wim:
```
mapview(natura2000, zcol = "n_occs",
legend = TRUE)
map <-
mapview(natura2000,
zcol = "n_occs", alpha.regions = 0.9, alpha = 0.2,
legend = TRUE, color = "red", map.types = c("OpenStreetMap"),
layer.name = c("n_obs"))
map
img <- "https://raw.githubusercontent.com/inbo/coding-club/master/docs/assets/images/coding_club_logo.svg"
map %>% leafem::addLogo(img, url = "https://inbo.github.io/coding-club/")
```
## Bonus challenge
Lynn
```
pal <- colorNumeric(palette = "viridis",
domain = natura2000$n_occs)
leaflet(data = natura2000) %>%
addTiles() %>%
addPolygons(fillColor = ~ pal(n_occs),
fillOpacity = 0.9,
stroke = T,
weight = 0.2,
color = "red",
label = ~ n_occs,
popup = ~ NAAM) %>%
addLegend(pal = pal,
values = ~ n_occs,
title = "n obs",
opacity = 1)
```