After completing Danielle’s tutorial videos, I attempted to implement everything I learnt with the ChickWeight data on R. The steps and codes I have used are as below:
library(tidyverse)
── Attaching packages ──────────────────────────────────────────── tidyverse 1.3.1 ──
✓ ggplot2 3.3.3 ✓ purrr 0.3.4
✓ tibble 3.1.2 ✓ dplyr 1.0.6
✓ tidyr 1.1.3 ✓ stringr 1.4.0
✓ readr 1.4.0 ✓ forcats 0.5.1
── Conflicts ─────────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag() masks stats::lag()
picture <- ggplot(
data = ChickWeight
) +
geom_point(
mapping = aes(
x = Time ,
y = weight,
)
)
plot(picture)
This tells us that over time, chicks’ weights are increasing - but not that informative… So let’s try to add the diet variable to find out which diet is most effective.
picture <- ggplot(
data = ChickWeight
) +
geom_point(
mapping = aes(
x = Time,
y = weight,
colour = Diet
)
) +
theme_minimal (
) +
scale_x_discrete (
name = "Time",
) +
scale_y_continuous(
name = "Chick Weight"
) +
ggtitle(
label = "Effect of Type of Diet on Chick Weight"
)
plot(picture)
Still a little confusing, so I am going to attempt to do this with a boxplot!
picture <- ggplot(
data = ChickWeight
) +
geom_boxplot(
mapping = aes(
x = Diet,
y = weight,
fill = Diet
)
) +
theme_minimal (
) +
scale_x_discrete (
labels = NULL,
name = NULL
) +
scale_y_continuous(
name = "Chick Weight"
) +
ggtitle(
label = "Effect of Type of Diet on Chick Weight"
) +
scale_fill_viridis_d(
alpha = 0.5,
) +
facet_wrap(vars(Time))
plot(picture)
This seems more interpretable!
On first glance: Diet has a more observable effect on chicks’ weights at later days. It looks like diets 3 and 4 produce heavier chicks than 1 and 2.
I had to Google a lot today, and had a lot of errors come up that I had to fix! But - I was also pleasantly surprised with the final outcome and how interpretable it was (positive reinforcement)!
This is actually quite fun! While it took me a long time to get my head around all the different things (and is still very much a work in progress), I look forward to practicing more of this and getting better at it.
Next up, I’m planning to watch the next playlist for Week 3 and get started on it this long weekend!