Code
library(tidyverse)
library(janitor)
library(googlesheets4)
library(tools)
Mara Alexeev
January 26, 2020
September 20, 2024
In May 2017 we fostered three kittens who were siblings. I tracked their daily weights out of curiosity and because I while I really enjoy fostering kittens, I would like some good rule of thumb for expected weight gain to help plan life around fostering (eg: Is this likely a 2 week or more of 4 week fostering gig?) The Maui Humane Society had specific weight cut offs for when kittens could be neutered (910 grams or 2 lbs), so for kittens that are socialized and healthy, this weight goal is the last hurdle before their neutering and being put up for adoption. Sadly, I don’t know how old the kittens were when we started fostering them, but I was able to find the foster request email from the shelter, and the director estimated the duration of fostering would be 4-5 weeks. Pretty amazing then that it only took 2 weeks, but maybe she just didn’t have the data to make good predictions on how long it takes kittens to gain weight.
The libraries I have loaded are tidyverse, janitor, googlesheets4 (this was added to the updated blog post and code in 2024), and tools. I tried to figure out if their was a code chuck option to show the code, but not show the evaluation of it, but didn’t find it. I’ll need to search through R Markdown. Update found it. Looks like I need to set message to false.
kitten_weight_gain <- clean_names(kitten_weight_gain)
tidy_kittens <- pivot_longer(kitten_weight_gain, cols = 3:5, names_to = "kitten_name", values_to = "weight_in_grams")
tidy_kittens <- tidy_kittens %>% separate(col = 4, into = c("kitten_name", "sex"), sep = "_")
tidy_kittens$sex <- as.factor(tidy_kittens$sex)
tidy_kittens$scale <- as.factor(tidy_kittens$scale)
tidy_kittens$date <- as.Date(tidy_kittens$date, format = "%m/%d/%Y")
tidy_kittens$weight_in_grams <- as.numeric(tidy_kittens$weight_in_grams)
tidy_kittens$kitten_name <- tools::toTitleCase(tidy_kittens$kitten_name)
#head(tidy_kittens)
Ok now I have my data in a more tidy format. This is the first time I have used dpylr::pivot_longer. I first tried to use dpylr::spread but saw a little note that pivot_longer was the new kid in town. I thought it was great. Certainly was faster for me to use even though it was the first time reading through the documentation.
I want to denote a few things in my graph: distinguish the two males from the female kitten, note that the first day’s wieght was by a different scale. And I’d love to somehow squeeze a picture of the kitten into its key–but since I only have a few minutes before my toddler wakes up–basics first.
graphic_kittens <- ggplot(tidy_kittens, aes(x = date, y = weight_in_grams, color = kitten_name, shape = sex)) +
geom_line() +
geom_point() +
labs(title = "Foster Kitten Weight Gain", subtitle = "Journey to adequate weight for neutering and adoption") +
xlab(" ") +
ylab("Weight in grams") +
theme_minimal() +
scale_x_date(date_breaks = "1 day", date_labels = "%b-%d")+
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(color = "Which kitten?") +
labs(shape = "Sex of kitten?")
print(graphic_kittens)
Questions I have now after the first collection of data:
Do males and females have different weight gain rates?
Do any animal shelters moniter weight gain as an indicator of kitten well being like we have for infant/child growth curves as humans?
What are the currently known determinants of weight gain in domestic kittens? Though these kittens were supposedly siblings, queens can have a single litter with multiple toms fathering kittens, so the kittens from a single litter might be more or less related.
---
title: Growing Kittens
author: 'Mara Alexeev'
date: 2020-01-26
date-modified: last-modified
categories: [R]
draft: false
description: How quickly do kittens gain weight?
slug: growing-kittens
image: 'image_for_blog_post.jpg'
archives:
- function () ,.Internal(date())
toc: true
format:
html:
code-fold: true
code-tools: true
---
![Reason, Rebel, Rhyme after their first bath.](images/kittens_after_bath.jpg)
# Fostering kittens
In May 2017 we fostered three kittens who were siblings. I tracked their daily weights out of curiosity and because I while I really enjoy fostering kittens, I would like some good rule of thumb for expected weight gain to help plan life around fostering (eg: Is this likely a 2 week or more of 4 week fostering gig?) The Maui Humane Society had specific weight cut offs for when kittens could be neutered (910 grams or 2 lbs), so for kittens that are socialized and healthy, this weight goal is the last hurdle before their neutering and being put up for adoption. Sadly, I don't know how old the kittens were when we started fostering them, but I was able to find the foster request email from the shelter, and the director estimated the duration of fostering would be 4-5 weeks. Pretty amazing then that it only took 2 weeks, but maybe she just didn't have the data to make good predictions on how long it takes kittens to gain weight.
## Import and tidy data
The libraries I have loaded are tidyverse, janitor, googlesheets4 (this was added to the updated blog post and code in 2024), and tools. I tried to figure out if their was a code chuck option to show the code, but not show the evaluation of it, but didn't find it. I'll need to search through R Markdown. **Update** found it. Looks like I need to set message to false.
```{r libraries, message = FALSE, warning=FALSE}
library(tidyverse)
library(janitor)
library(googlesheets4)
library(tools)
```
```{r import data, message = FALSE, warning=FALSE}
#Read google sheets data into R
kitten_weight_gain <- read_sheet('https://docs.google.com/spreadsheets/d/1x-Udhm5VkhSh0siWLtipbDZFAMs5Zp7TsTpnUlmz9Jg/edit?gid=0#gid=0')
#names(kitten_weight_gain)
```
```{r tidy data to make each row an observation, message = FALSE, warning=FALSE}
kitten_weight_gain <- clean_names(kitten_weight_gain)
tidy_kittens <- pivot_longer(kitten_weight_gain, cols = 3:5, names_to = "kitten_name", values_to = "weight_in_grams")
tidy_kittens <- tidy_kittens %>% separate(col = 4, into = c("kitten_name", "sex"), sep = "_")
tidy_kittens$sex <- as.factor(tidy_kittens$sex)
tidy_kittens$scale <- as.factor(tidy_kittens$scale)
tidy_kittens$date <- as.Date(tidy_kittens$date, format = "%m/%d/%Y")
tidy_kittens$weight_in_grams <- as.numeric(tidy_kittens$weight_in_grams)
tidy_kittens$kitten_name <- tools::toTitleCase(tidy_kittens$kitten_name)
#head(tidy_kittens)
```
Ok now I have my data in a more tidy format. This is the first time I have used dpylr::pivot_longer. I first tried to use dpylr::spread but saw a little note that pivot_longer was the new kid in town. I thought it was great. Certainly was faster for me to use even though it was the first time reading through the documentation.
## Weight gain, graphically
I want to denote a few things in my graph: distinguish the two males from the female kitten, note that the first day's wieght was by a different scale. And I'd love to somehow squeeze a picture of the kitten into its key--but since I only have a few minutes before my toddler wakes up--basics first.
```{r}
graphic_kittens <- ggplot(tidy_kittens, aes(x = date, y = weight_in_grams, color = kitten_name, shape = sex)) +
geom_line() +
geom_point() +
labs(title = "Foster Kitten Weight Gain", subtitle = "Journey to adequate weight for neutering and adoption") +
xlab(" ") +
ylab("Weight in grams") +
theme_minimal() +
scale_x_date(date_breaks = "1 day", date_labels = "%b-%d")+
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(color = "Which kitten?") +
labs(shape = "Sex of kitten?")
print(graphic_kittens)
```
## Next steps
Questions I have now after the first collection of data:
Do males and females have different weight gain rates?
Do any animal shelters moniter weight gain as an indicator of kitten well being like we have for infant/child growth curves as humans?
What are the currently known determinants of weight gain in domestic kittens? Though these kittens were supposedly siblings, queens can have a single litter with multiple toms fathering kittens, so the kittens from a single litter might be more or less related.