owned this note
owned this note
Published
Linked with GitHub
# INBO CODING CLUB
24 November 2020
Welcome! Welcome! 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 | ***
Emma Cartuyvels |***
Lynn Pallemaerts | **
Patrik Oosterlynck | ***
Joost Vanoverbeke | ***
An Leyssen | **
Hans Van Calster | ***
Mathias Wackenier|***
Amber Mertens | ***
Arno Thomaes|*
Anja Leyman |***
## Challenge 1
Damiano's solution:
```
ggplot(data) +
```
Joost:
```
CO2 %>%
ggplot(aes(conc, uptake, color = Treatment, shape = Type)) +
geom_point() +
labs(title = "cold tolerance of the grass species Echinochloa crus-galli",
y = "CO2 uptake") +
scale_x_log10() +
scale_color_manual(values = c("indian red", "blue"))
```
Emma:
```
ggplot(CO2, aes(x = conc, y = uptake)) +
geom_point(aes(colour = Treatment, shape = Type)) +
labs(y = "CO2 uptake",
title = "cold tolerance of the grass species \n Echinochloa crus-galli") +
scale_x_log10() +
scale_color_manual(values = c("indian red", "blue"))
```
Anja:
```
ggplot (data = CO2, aes(x = conc,
y = uptake,
color = Treatment,
shape = Type)) +
geom_point() +
ylab("CO2 uptake") +
ggtitle("cold tolerance of the grass species Echinochloa crus-galli") +
scale_x_log10() +
scale_color_manual(values=c("indian red", "blue"))
```
Patrik:
```
ggplot(data = CO2, aes(y = uptake, x = conc)) +
geom_point(aes(color = Treatment, shape = Type)) +
ylab("CO2 uptake") +
ggtitle("Cold tolerance of the grass species Echinochloa crus-galli") +
scale_x_log10() +
scale_color_manual(values=c("indian red", "blue"))
```
Lynn:
```
ggplot(data=CO2,
mapping=aes(x=conc, y=uptake, color=Treatment)) +
geom_point(aes(shape=factor(Type))) +
ylab("CO2 uptake") +
ggtitle("Cold tolerance of the grass species Echinochloa crus-galli") +
scale_x_log10() +
scale_color_manual(values=c("blue","indian red"))
```
Hans:
```
ggplot(CO2) +
geom_point(aes(x = conc, y = uptake, color = Treatment, shape = Type)) +
scale_x_log10(breaks = c(100, 200, 500, 1000)) +
scale_color_manual(values = c("nonchilled" = "indian red", "chilled" = "blue")) +
labs(y = "C02 uptake",
x = "Concentration",
title = expression(
paste("Cold tolerance of the grass species ",
italic("Echinochloa crus-galli")))
)
```
Amber:
```
ggplot(data = CO2,
mapping = aes(x = conc, y = uptake, color = Treatment, shape = Type)) +
geom_point() +
scale_x_log10() +
labs(title = "Cold tolerance of the grass species Echinochloa crus-galli",
ylab = "CO2 uptake") +
scale_fill_manual(values = c("blue", "indian red"))
```
### Dirk
Met aanpassen van achtergrond en tekstgrootte op de assen):
```
p <- ggplot(CO2,
aes(x = conc,
y = uptake,
colour = Treatment,
cex = Type)) +
geom_point() +
ggtitle("Cold tolerance of the grass species Echinochloa crus-galli") +
scale_y_log10() +
scale_color_manual(values = c("chilled" = "blue",
"nonchilled" = "indian red")) +
xlab("Concentration") +
ylab("CO2 uptake") +
theme(axis.text.x = element_text(angle = 45,
hjust = 1),
axis.text = element_text(size = 20),
axis.title = element_text(size = 25,
face = "bold"),
legend.text = element_text(size = 20),
legend.title = element_text(size = 20),
panel.background = element_rect(fill = "white",
colour = "grey",
size = 1,
linetype = "solid"),
panel.grid.major = element_line(size = 0.5,
linetype = "solid",
colour = "grey"),
strip.text = element_text(size = 15,
face = "bold"),
plot.title = element_text(size = 20,
face = "bold"))
p
```
An:
```
ggplot(data = CO2,
mapping = aes(x = conc, y = uptake,
color = Treatment, shape = Type)) +
geom_point() +
ylab("CO2 uptake") +
ggtitle("cold tolerance of the grass species Echinochloa crus-galli") +
scale_x_log10() +
scale_colour_manual(values = c("chilled" = "blue", "nonchilled" = "indian red"))
```
## INTERMEZZO
### Example 1
```
# option 1 (make changes to aesthetics of second geomtry)
ggplot(CO2, aes(x = conc, y = uptake, color = Type)) +
geom_violin() +
geom_violin(aes(color = NULL), alpha = 0.5)
# option 2 (specify both aesthetics separately)
ggplot(CO2) +
geom_violin(aes(x = conc, y = uptake, color = Type)) +
geom_violin(aes(x = conc, y = uptake), alpha = 0.5)
# option 3 (specify first the common part of the two aesthetics)
ggplot(CO2, aes(x = conc, y = uptake)) +
geom_violin(aes(color = Type)) +
geom_violin(alpha = 0.5)
```
### Example 2
```
# option 1 (make changes to aesthetics of second geomtry)
ggplot(CO2, aes(x= conc, y = uptake, color = Type, group = Plant)) +
geom_line() +
geom_smooth(aes(group = NULL, fill = Type))
#option 2 (specify both aesthetics separately)
ggplot(CO2) +
geom_line(aes(x= conc, y = uptake, color = Type, group = Plant)) +
geom_smooth(aes(x= conc, y = uptake, color = Type, fill = Type))
# option 3 (specify first the common part of the two aesthetics)
ggplot(CO2, aes(x= conc, y = uptake, color = Type)) +
geom_line(aes(group = Plant)) +
geom_smooth(aes(fill = Type))
```
## Challenge 2
Emma:
```
ggplot(CO2, aes(x = conc, y = uptake)) +
geom_point(color = "green", alpha = 0.1)
ggplot(CO2, aes(x = as.factor(conc), y = uptake, fill = Treatment)) +
geom_boxplot()
```
Hans:
```
ggplot(CO2, aes(x = conc, y = uptake)) +
geom_point(color = "green", alpha = 0.5)
ggplot(CO2, aes(x = conc, y = uptake)) +
geom_boxplot(aes(group = factor(conc):Treatment,
color = Treatment))
```
Lynn:
```
ggplot(CO2, aes(x = conc,
y = uptake)) +
geom_point(aes(alpha=0.1)) +
scale_colour_manual(values = c("green"))
ggplot(CO2, aes(x = Treatment,
y = uptake,
color=Type )) +
geom_boxplot()
```
Amber:
```
ggplot(CO2, aes(x = conc, y = uptake)) +
geom_point(color = "green", alpha = 0.1)
ggplot(CO2, aes(x = as.factor(conc), y = uptake, color = Treatment)) +
geom_boxplot()
```
Dirk:
```
p <- ggplot(CO2,
aes(x = factor(conc),
y = uptake,
color = Treatment)) +
geom_boxplot() +
ggtitle("Cold tolerance of the grass species Echinochloa crus-galli") +
scale_y_log10() +
scale_color_manual(values = c("chilled" = "blue",
"nonchilled" = "indian red")) +
xlab("Concentration") +
ylab("CO2 uptake") +
theme(axis.text.x = element_text(angle = 45,
hjust = 1),
axis.text = element_text(size = 20),
axis.title = element_text(size = 25,
face = "bold"),
legend.text = element_text(size = 20),
legend.title = element_text(size = 20),
panel.background = element_rect(fill = "white",
colour = "grey",
size = 1,
linetype = "solid"),
panel.grid.major = element_line(size = 0.5,
linetype = "solid",
colour = "grey"),
strip.text = element_text(size = 15,
face = "bold"),
plot.title = element_text(size = 20,
face = "bold"))
p
```
Mathias
```
#2.1
ggplot(CO2, aes(x = conc, y = uptake)) +
geom_point(color = "green",
alpha = 0.1)
#2.2
ggplot(CO2, aes(x = Type, y = uptake))+
geom_boxplot()+
ggtitle("CO2 uptake of the grass species Echinochloa crus-galli per type per treatment")
facet_grid(rows = vars(Treatment))+
theme(strip.text.y = element_text(angle = 0))
```
## Challenge 3
Emma:
```
ggplot(CO2, aes(x = conc, y = uptake, color = Treatment, shape = Type)) +
geom_point() +
facet_wrap(~Plant)
area_biotopes <- read_csv("./data/20201124/20201124_area_biotopes.txt",
na = "")
library(INBOtheme)
# New facet label names for region variable
region.labs <- c("Flanders", "South-Netherland", "North-Netherland")
names(region.labs) <- c("FL", "NL_South", "NL_North")
ggplot(area_biotopes,
aes(x = year,
y = meanArea,
colour = species)) +
geom_pointrange(aes(ymin = meanArea - seArea,
ymax = meanArea + seArea)) +
geom_smooth(se = FALSE) +
facet_grid(biotope~region,
labeller = labeller(region = region.labs))
```
Amber:
```
ggplot(CO2, aes(x = conc, y = uptake, color = Treatment, shape = Type)) +
geom_point() +
facet_wrap(~ Plant)
ggplot(area_biotopes,
aes(x = year,
y = meanArea,
colour = species)) +
geom_pointrange(aes(ymin = meanArea - seArea,
ymax = meanArea + seArea)) +
geom_smooth() +
facet_grid(biotope ~ region)
```
Lynn:
```
ggplot(CO2, aes(x = conc, y = uptake, color = Treatment, shape = Type)) +
geom_point() +
facet_wrap("Plant")
```
Hans:
```
ggplot(CO2, aes(x = conc, y = uptake, color = Treatment, shape = Type)) +
geom_point() +
facet_wrap(~ Plant)
library(INBOtheme)
ggplot(area_biotopes,
aes(x = year,
y = meanArea,
colour = species)) +
geom_pointrange(aes(ymin = meanArea - seArea,
ymax = meanArea + seArea)) +
facet_grid(biotope ~ region,
scales = "free") +
geom_smooth(se = FALSE)
```
Anja
```
ggplot(CO2, aes(x = conc, y = uptake, color = Treatment, shape = Type)) +
geom_point() +
facet_wrap(~Plant)
```
```ggplot(area_biotopes,
aes(x = year,
y = meanArea,
colour = species)) +
geom_pointrange(aes(ymin = meanArea - seArea,
ymax = meanArea + seArea)) +
geom_smooth(se = FALSE) +
scale_color_manual(values=c("green", "blue")) +
facet_grid(biotope~region)
```
Mathias
```
#3.1
ggplot(CO2, aes(x = conc, y = uptake, color = Treatment, shape = Type)) +
geom_point()+
facet_wrap(vars(Plant))
#3.2
ggplot(area_biotopes,
aes(x = year,
y = meanArea,
colour = species)) +
geom_pointrange(aes(ymin = meanArea - seArea,
ymax = meanArea + seArea))+
geom_smooth(se = FALSE)+
facet_grid(biotope~region, scales = "free")
```
## Bonus challenge
Emma:
```
ggplot(CO2, aes(y = uptake, fill = Treatment:Type)) +
geom_boxplot(aes(group = Treatment:Type))
ggplot(CO2, aes(x = as.factor(conc), y = uptake)) +
geom_boxplot() +
facet_grid(Type~Treatment)
```
Hans:
```
ggplot(CO2) +
geom_boxplot(aes(x = conc,
y = uptake,
group = factor(conc):Type:Treatment,
color = interaction(Type, Treatment, sep = "-"))) +
labs(x = "concentration", color = "Type-Treatment")
```
Anja
```
ggplot(CO2, aes(x = as.factor(conc),
y = uptake)) +
geom_boxplot(aes(color = Type:Treatment))
```
Amber:
```
ggplot(CO2, aes(x = as.factor(conc), y = uptake, color = Type:Treatment)) +
geom_boxplot()
```