owned this note
owned this note
Published
Linked with GitHub
# INBO CODING CLUB
31 August 2021
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 | *
Tom De Dobbelaer | *
Dirk Maes | *
Hans Van Calster | *
Marijke Thoonen | *
Bram D'hondt |
Joost Vanoverbeke | ***
Matthieu Chastel|*
Emily Veltjen |
Amber Mertens | *
Adriaan Seynaeve |
## Challenge 1
Damiano's solution:
joost
```
ToothGrowth %>%
ggplot(aes(dose, len)) +
geom_point(aes(color = supp, shape = supp)) +
labs(x = "dose (mg/day)",
y = "length (mm)",
title = "The Effect of Vitamin C on Tooth Growth in Guinea Pigs") +
scale_color_manual(values = c("OJ" = "blue", "VC" = "indian red"))
```
Dirk (long version ... , with all kinds of fancy things to make it nicer :-D, but probably not the best way of scripting in ggplot)
```
p <- ggplot(ToothGrowth,
aes(x = dose,
y = len,
colour = supp,
shape = supp)) +
geom_point() +
geom_point(size = 5) +
labs(x = "dose (mg/day)",
y = "length (mm)",
title = "The Effect of Vitamin C on Tooth Growth in Guinea Pigs",
colour = "Supplement",
shape = "Supplement") +
theme(axis.text.x = element_text(angle = 45,
hjust = 0.5,
vjust = 0.5),
axis.text.y = element_text(angle = 0,
hjust = 0),
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")) +
scale_colour_manual(values = c("OJ" = "blue",
"VC" = "indianred"))
p
```
Bram
```
ggplot(data=ToothGrowth,
mapping = aes(x=dose,
y=len)) +
geom_point(aes(color=supp)) +
ylab("length (mm)") +
xlab("dose(mg/day)") +
ggtitle("The Effect of Vitamin C on Tooth Growth in Guinea Pigs")
```
## Challenge 2
Dirk (long version again)
```
ToothGrowth$fdose <- as.factor(ToothGrowth$dose)
ToothGrowth$fsupp <- as.factor(ToothGrowth$supp)
p <- ggplot(ToothGrowth, aes(x = fdose,
y = len,
group = fdose:fsupp,
colour = fsupp)) +
geom_boxplot() +
labs(x = "dose (mg/day)",
y = "length (mm)",
title = "The Effect of Vitamin C on Tooth Growth in Guinea Pigs",
colour = "Supplement") +
theme(axis.text.x = element_text(angle = 45,
hjust = 0.5,
vjust = 0.5),
axis.text.y = element_text(angle = 0,
hjust = 0),
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"))
p
```
joost challenge 2B
```
Orange %>%
ggplot(aes(age, circumference)) +
geom_smooth(aes(color = ordered(as.numeric(as.character(Tree)))), se = FALSE) +
geom_smooth(color = "red", size = 2) +
labs(color = "Tree")
```
## INTERMEZZO
## Challenge 3
Marijke
'''
ggplot(Orange)+
geom_smooth(aes(x = age, y = circumference)) +
facet_grid(.~Tree)'''
Joost
```
Orange %>%
mutate(Tree = ordered(as.numeric(as.character(Tree)))) %>%
ggplot(aes(age, circumference)) +
geom_smooth() +
facet_wrap(~ Tree, labeller = "label_both")
hair_eye_color_df %>%
ggplot(aes(Hair, Freq)) +
geom_col(aes(fill = Sex), position = "dodge") +
facet_wrap(~Eye, labeller = "label_both")
hair_eye_color_df %>%
ggplot(aes(Hair, Freq)) +
geom_col() +
facet_grid(Sex~Eye, labeller = "label_both") +
theme(axis.text.x = element_text(angle = 90))
```
Emily
t <- ggplot(Orange)+geom_smooth(aes(x = age, y = circumference, color = Tree), se=FALSE)
t+facet_grid(cols=vars(Tree))
## Bonus challenge