owned this note
owned this note
Published
Linked with GitHub
# INBO CODING CLUB
29 September 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
--- | ---
Silke Dupont |
Damiano Oldoni | ***
Leyman Anja |
Hans Van Calster |
Dirk Maes |
Emma Cartuyvels|
An Leyssen |
Sarah Broos|
Luc De Bruyn | ***
Raïsa Carmen | ***
## Challenge 1
Emma:
```
# 2. How to use it for `usecase1`?
usecase1 +
scale_color_manual(values = c("#16DF6E","#87D73D","#C2CB16","#F1BA1B"))
# 3. How to use it for `usecase3`?
usecase3 +
scale_fill_gradientn(colours = c("#16DF6E","#87D73D","#C2CB16","#F1BA1B"))
# 4. How to invert the color scale of `usecase3`?
usecase3 +
scale_fill_gradientn(colours = c("#16DF6E","#87D73D","#C2CB16","#F1BA1B"),
trans = "reverse")
# 5.
library(INBOtheme)
usecase3 +
scale_fill_gradientn(colours = inbo_palette(4),
trans = "reverse")
```
Dirk
```
usecase1 <-
ggplot(area_biotopes_pararge,
aes(x = year,
y = meanArea,
color = biotope)) +
geom_point() +
geom_smooth() +
labs(title = "Distribution of Pararge aegeria",
y = "Area (%)",
color = "BIOTOPE") +
facet_wrap(~ region) +
scale_colour_manual(values = c("Agriculture" = "black", "Forest" = "darkred", "Open" = "orange", "Urban" = "yellow"))
usecase1
```
## INTERMEZZO
## Challenge 2
Emma:
```
## CHALLENGE 2: combine separate ggplots with `patchwork`
# 1. Display `usecase1` and `usecase2` next to each other
usecase1 + usecase2
# 2. Display `usecase2` below `usecase1`
usecase1/usecase2
# 3. Display `usecase1` and `usecase2`in first row and `usecase3` and
# `usecase4` in the second row creating a 2x2 plot grid.
(usecase1 + usecase2) / (usecase3 + usecase4)
# 4. `usecase1` and `usecase2` share same legend. How to avoid duplicating
# it in 1 and 2? Check [guides controlling section](https://patchwork.data-imaginist.com/articles/guides/layout.html#controlling-guides)
# of "Controlloing Layout" vignette
(usecase1 + usecase2) / (usecase3 + usecase4) +
plot_layout(guides = 'collect')
# 5. What if you try to avoid duplicating the legend of `usecase3` and
# `usecase4`? Can you understand why? How to solve it? Hint: _scale_ your
# plots, check ggplot cheatsheet!
(usecase1 + usecase2) / (usecase3 + scale_fill_continuous(limits = c(0,75)) + usecase4 + scale_fill_continuous(limits = c(0,75))) +
plot_layout(guides = 'collect')
# 6. Display `usecase3` on the left and a table with the displayed data
# (species, region, biotope, meanArea) on the right. Hint: check this
# [vignette](https://patchwork.data-imaginist.com/articles/guides/assembly.html#adding-non-ggplot-content).
usecase3 + gridExtra::tableGrob(area_biotopes_2000)
```
Luc:
Werkt blijkbaar ook met flextable. Layout kan waarschijnlijk beter, maar het is mijn eerste prentje met patchwork :)
```
library(flextable)
usecase3$data %>%
group_by(species) %>%
summarise(n = n()) %>%
qflextable() %>%
gen_grob() -> t1
usecase3 + (plot_spacer() / t1 / plot_spacer())
```
## Challenge 3