owned this note
owned this note
Published
Linked with GitHub
# INBO CODING CLUB
25 April 2023
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 | ***
Emma Cartuyvels|
Dirk Maes | **
Ward Langeraert | **
Marijke Thoonen |
Amber Mertens | **
Oberon Geunens |**
Jonas Bertels | **
Raïsa Carmen | ***
## Challenge 1
### Solution Ward
```r
library(INBOtheme)
# 1
ias_first_obs_be + ias_first_obs_reg
# 2
ias_first_obs_be / ias_first_obs_reg
# 3
ias_first_obs_reg_facets <- ias_first_obs_reg +
facet_wrap(~locationId) +
theme(legend.position = "bottom")
ias_first_obs_be / ias_first_obs_reg_facets
# 4
ias_first_obs_be_facets <- ias_first_obs_be +
facet_wrap(~kingdom)
ias_first_obs_reg_facets2 <- ias_first_obs_reg_facets +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
(ias_first_obs_be / ias_first_obs_reg_facets2) | ias_first_obs_be_facets
# 5
tab <- ias_regions %>%
count(locationId) %>%
arrange(locationId)
ias_first_obs_reg_facets2 + gridExtra::tableGrob(tab)
```
### Solution Emma:
```
ias_first_obs_be | ias_first_obs_reg
ias_first_obs_be / ias_first_obs_reg
ias_first_obs_reg_facets <- ias_first_obs_reg + facet_grid(cols = vars(locationId))
ias_first_obs_be / ias_first_obs_reg_facets
ias_first_obs_be_facets <- ias_first_obs_be + facet_wrap(vars(kingdom))
(ias_first_obs_be / ias_first_obs_reg_facets) | ias_first_obs_be_facets
table <- ias_regions %>%
group_by(locationId) %>%
summarise(sum = n())
ias_first_obs_reg_facets | gridExtra::tableGrob(table)
```
### Solution Jonas:
```
#
ias_first_obs_be + ias_first_obs_reg
#
ias_first_obs_be / ias_first_obs_reg
#
ias_first_obs_reg_facet <- ias_first_obs_reg +
facet_grid(.~locationId)
ias_first_obs_reg_facet
ias_first_obs_be / ias_first_obs_reg_facet
#
ias_first_obs_be_facet <- ias_first_obs_be +
facet_grid(kingdom~.)
ias_first_obs_be_facet
ias_first_obs_reg_facet_2 <- ias_first_obs_reg +
facet_grid(locationId~.) +
theme(legend.position = "none")
ias_first_obs_reg_facet_2 + ias_first_obs_be_facet
#
ias_first_obs_reg_facet +
theme(legend.position = "none") +
gridExtra::tableGrob(count(ias_regions, locationId))
```
## Challenge 2
### Solution Ward
```r
# 1
ias_first_obs_paths +
facet_zoom(xlim = c(1980, 2000), ylim = c(0, 100))
# 2
ias_first_obs_reg +
facet_wrap_paginate(~kingdom, strip.position = "bottom") +
theme(legend.position = "top") +
labs(x = "", y = "aantal", fill = "locatie")
```
### Solution Marijke
'''
#1
ias_first_obs_paths + facet_zoom(xlim = c(1980, 2000))
'''
### Solution Jonas:
```
#
ias_first_obs_paths +
facet_zoom(x = first_observed >= 1980 &
first_observed <= 2000)
ias_first_obs_paths +
facet_zoom(x = first_observed >= 1980 &
first_observed <= 2000,
y = n < 50,
split = TRUE)
#
ias_first_obs_reg_facet_force <- ias_first_obs_reg +
facet_col(~locationId, scales = 'free', strip.position = 'bottom')
ias_first_obs_reg_facet_force
```
## Challenge 3
Solution Raisa
```r
#1
ggplotly(ias_first_obs_paths)
#2
ggplotly(ias_first_obs_paths, dynamicTcisk = TRUE)
#3
ias_first_obs_paths_labelled <-
ggplot(ias_pathways,
aes(text = paste('year: ', first_observed,
'\nintroduction pathway:', pathway,
'\nnumber of taxa: ', n))) +
geom_point(mapping = aes(x = first_observed,
y = n,
color = pathway),
shape = 1,
size = 3) +
geom_line(mapping = aes(x = first_observed,
y = n,
# group argument tells R which points have to be linked together to form a line
group = pathway,
color = pathway)) +
labs(x = "year of introduction", y = "number of taxa") +
theme(axis.text.x = element_text(angle = 70, vjust = 0.5))
ggplotly(ias_first_obs_paths_labelled, dynamicTcisk = TRUE,
tooltip = "text")
```
### Solution Ward
```r
# challenge 3A
p <- area_biotopes %>%
ggplot(aes(x = species, y = meanArea)) +
geom_point(aes(colour = biotope, size = meanArea)) +
facet_wrap(~region) +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
labs(title = 'Year: {frame_time}') +
transition_time(year) +
ease_aes("cubic-in-out")
# Save as GIF
library(gifski)
anim_save("area_biotopes.GIF", animation = p, renderer = gifski_renderer(),
width = 1000, height = 300, path = "src/20230425")
# Save as mp4
library(av)
anim_save("area_biotopes.mp4", animation = p, renderer = av_renderer(),
width = 1000, height = 300, path = "src/20230425")
```