Code
library(tidyverse)
library(conflicted)
library(readr)
library(tidyr)
library(dplyr)
library(patchwork)library(tidyverse)
library(conflicted)
library(readr)
library(tidyr)
library(dplyr)
library(patchwork)A test was conducted to evaluate how different dietary treatments influenced litter weight gain and the reproductive performance of sows at the following farrowing cycle (Henman et al., 2023). I chose this data-set to focus on as the relationship between the several average weight data-sets and the treatment data-set was extremely interesting. Taking a look between the relationship of these variables will provide insight to what treatment is best for a heavier litter.
I wish to investigate the correlation between what diet the mother is fed, and whether the feed affects the weight of the piglets overtime. I am also interested what feed makes the litter the heaviest and how it compares to a litter with a normal diet.
Therefore I would like to know:
To address these questions, I will analyse the following variables:
Treatment = Categorical (Nominal)
Average weight kg = Numerical
Average weight D3 kg = Numerical
Average weight D14 = Numerical
Average wean weight = Numerical
The treatment variable will help me to compare the treatments that each sow receives and therefore connect that with how much weight a piglet has gained.
The average weight variable is the initial weight that the piglets are born in.
The average weight D3 and D14 variable will allow for me to view how the litter weight has increased overtime.
The average wean weight is the last variable provided, and will show the ‘end result’ of the piglets weight.
sows_data <- read_csv('/Users/sabrinagarcia/Desktop/envx/assignment/Describing Data Report/sows.csv')
sows_data$Treatment <- factor(sows_data$Treatment)
str(sows_data)spc_tbl_ [144 × 8] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
$ Parity : num [1:144] 3 3 3 4 3 3 3 3 3 4 ...
$ Treatment : Factor w/ 3 levels "A","B","C": 1 1 1 1 1 1 1 1 1 1 ...
$ Total_Born : num [1:144] 9 7 14 12 8 14 12 9 11 13 ...
$ Born_Alive : num [1:144] 7 7 12 12 8 13 11 9 10 10 ...
$ Average_weight_kg : num [1:144] 1.4 1.671 1.436 0.953 1.562 ...
$ Average_weight_D3_kg : num [1:144] 1.7 2.23 1.31 1.8 1.9 ...
$ Average_weight_D14_kg : num [1:144] 5.26 4.76 4.03 5.47 3.35 ...
$ Average_wean_weight_kg: num [1:144] 9.14 7.51 7.62 8.43 4.92 ...
- attr(*, "spec")=
.. cols(
.. Parity = col_double(),
.. Treatment = col_character(),
.. Total_Born = col_double(),
.. Born_Alive = col_double(),
.. Average_weight_kg = col_double(),
.. Average_weight_D3_kg = col_double(),
.. Average_weight_D14_kg = col_double(),
.. Average_wean_weight_kg = col_double()
.. )
- attr(*, "problems")=<externalptr>
I will first analyse and compare the average weights of the litter at each recorded checkpoint using a histogram and the summary function.
ggplot(sows_data, aes(x = Average_weight_kg)) +
geom_histogram (bins = 25 , fill = "rosybrown2" , color = "rosybrown" ) +
labs(
title = "Average Litter Weight Upon Birth",
x = "Weight (Kg)",
y = "Litter Count"
)summary(sows_data$Average_weight_kg) Min. 1st Qu. Median Mean 3rd Qu. Max.
0.9533 1.4138 1.5375 1.5662 1.6917 2.2750
Visually, piglets within this litter range from being 0.5kg-2.4kgs seen in @avg-weight-birth
ggplot(sows_data, aes(x = Average_weight_D3_kg)) +
geom_histogram (bins = 25 , fill = "rosybrown2" , color = "rosybrown" ) +
labs(
title = "Average Litter Weight, 3 Days After Birth",
x = "Weight (Kg)",
y = "Litter Count"
)summary(sows_data$Average_weight_D3_kg) Min. 1st Qu. Median Mean 3rd Qu. Max.
1.111 1.838 2.000 2.002 2.214 2.944
ggplot(sows_data, aes(x = Average_weight_D14_kg)) +
geom_histogram (bins = 25 , fill = "rosybrown2" , color = "rosybrown" ) +
labs(
title = "Average Litter Weight, 14 Days After Birth",
x = "Weight (Kg)",
y = "Litter Count"
)summary(sows_data$Average_weight_D14_kg) Min. 1st Qu. Median Mean 3rd Qu. Max.
2.900 4.418 4.941 4.888 5.367 6.425
ggplot(sows_data, aes(x = Average_wean_weight_kg)) +
geom_histogram (bins = 25 , fill = "rosybrown2" , color = "rosybrown" ) +
labs(
title = "Average Litter weight, when Weaned",
x = "Weight (Kg)",
y = "Litter Count"
)summary(sows_data$Average_wean_weight_kg) Min. 1st Qu. Median Mean 3rd Qu. Max.
4.917 7.378 7.893 7.995 8.647 11.475
p1 <- ggplot(sows_data, aes(x = Treatment, y = Average_weight_kg)) +
geom_boxplot( fill = "rosybrown1" , color = "rosybrown3") +
labs(
title = "Avg. Birthweight of Piglets",
x = "Treatment Types",
y = "Weight (Kg)"
)
#| label: box-avg-weight-d3
p2 <- ggplot(sows_data, aes(x = Treatment, y = Average_weight_D3_kg)) +
geom_boxplot( fill = "rosybrown2" , color = "rosybrown") +
labs(
title = "Avg. Weight of Piglets, D3",
x = "Treatment",
y = "Weight (Kg)"
)
#| label: box-avg-weight-d14
p3 <- ggplot(sows_data, aes(x = Treatment, y = Average_weight_D14_kg)) +
geom_boxplot( fill = "rosybrown3" , color = "rosybrown4") +
labs(
title = "Avg. Weight of Piglets, D14",
x = "Treatment",
y = "Weight (Kg)"
)
#| label: box-avg-weight-weaned
p4 <- ggplot(sows_data, aes(x = Treatment, y = Average_wean_weight_kg)) +
geom_boxplot( fill = "rosybrown" , color = "rosybrown4") +
labs(
title = "Avg. Weight of Piglets, Weaned",
x = "Treatment Types",
y = "Weight (Kg)"
)
(p1 + p2) / (p3 + p4)sows_long <- sows_data |>
select(Treatment,
Average_weight_kg,
Average_weight_D3_kg,
Average_weight_D14_kg,
Average_wean_weight_kg) |>
pivot_longer(
cols = -Treatment,
names_to = "Timepoint",
values_to = "Weight_kg"
) |>
mutate(
Day = case_when(
Timepoint == "Average_weight_kg" ~ 0,
Timepoint == "Average_weight_D3_kg" ~ 3,
Timepoint == "Average_weight_D14_kg" ~ 14,
Timepoint == "Average_wean_weight_kg" ~ 28
),
Treatment = factor(Treatment, levels = c("A", "B", "C"))
)
p <- ggplot(sows_long, aes(x = Day, y = Weight_kg, colour = Treatment)) +
geom_jitter(alpha = 0.40, size = 2, width = 1) +
stat_summary(fun = mean, geom = "line", linewidth = 1.1, aes(group = Treatment)) +
stat_summary(fun = mean, geom = "point", size = 3.5, shape = 18) +
scale_x_continuous(
breaks = c(0, 3, 14, 28),
labels = c("Day 0\n(Birth)", "Day 3", "Day 14", "Day 28\n(Weaning)")
) +
scale_colour_manual(
values = c("A" = "rosybrown1", "B" = "rosybrown", "C" = "rosybrown4"),
name = "Treatment"
) +
labs(
title = "Piglet Growth from Birth to Weaning by Diet",
subtitle = "Points = individual litter means | Diamond + line = treatment mean",
x = "Days",
y = "Average Weight (kg)"
) +
theme_bw(base_size = 13) +
theme(
plot.title = element_text(face = "bold", size = 14),
plot.subtitle = element_text(colour = "grey40", size = 10),
legend.position = "right",
panel.grid.minor = element_blank()
)
p The study only recorded until piglets were at the weaning stage, around 21 days — and does not go beyond that. It would’ve been useful to see the long term effects of the diet, and see if there is any increase or decrease in weight after being weaned.
Anthropic. (2023). Claude. Claude.ai. https://claude.ai
Henman, D., Lean, I. J., Block, E., & Golder, H. M. (2023). Data on the effects of the anionic protein meal BioChlorⓇ on sows before and after farrowing. Data in Brief, 48, 109168. https://doi.org/10.1016/j.dib.2023.109168
Throughout this task, I did find several small aspects of this tasks slightly difficult and confusing — such as having my code not work based off of one several small errors. Furthermore it was a bit challenging to keep within the word limit as in the scatterplot section, I could not specifically point out a box plot without increasing my word count
I used Claude for troubleshooting errors in my code (specifically the YAML), and to help create the scatterplot, as I wanted to visualise the data in a way that went beyond the functions covered in the practicals. I relied on Claude as a trusted source as it has strong reasoning when providing responses.
Henman et al., 2023 was the source of my dataset, and allowed for me to understand the dataset further, as I initially thought that the piglets were being fed the treatment directly.
I also acknowledge that I did have to ask for help on ED Discussion for assistance with the code for the histographs, as I had made the numerical data factors.