library(lubridate)
library(zoo)
library(ggplot2)
library(tidyverse)
library(googlesheets4)
library(ggrepel)
library(scales)
library(readr)Cat plots
We have two cats, Satsuma and Miso. They are the best.
Every few days we weigh them because I’m neurotic like that, and I want to see if they’re growing how they should :)
Based on this I have made some cat plots.
Load packages
Load CatPlot functions
The calculations and plots are all produced with custom functions.
source("cat_plots_functions.R")
source("cat_centiles_functions.R")Import data
There are two sets of data we care about:
- cat_weights. This is measurements of our cat’s weights in kg, along with the day the measurement was taken.
- male and female centiles for cat growth. I calculated these using gamlss on a dataset of around 90,000 observations of weighing cats, using some data that some nice people at the university of liverpool have made available to the public: https://datacat.liverpool.ac.uk/1456/1/KGC1_dataset.csv. (I ran this offline and published the results on google drive because it takes a couple of minutes to run and no one needs that)
cat_weights <- import_cat_weights()
male_centiles <- read.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vQE1gsGzYccmUdWJLJ3yrxotIr7Dzp_usiz10iPMVQj9aKtuhjW2TzBFhPoTnBAQGpbNSx_YtO1z5X8/pub?output=csv",
header = TRUE) |> janitor::clean_names()
female_centiles <- read.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vTs75qWQB0SrMIl-ZNOiRwt3WG-I1WMJoCjfZtuTolGblFgu7BdgI_ZqKaQng_HqjxhEut5-Bq0QNwK/pub?output=csv",
header = TRUE) |> janitor::clean_names()Generate plots
Here we run all the custom functions, which generate all the plots
cat_weights <- import_cat_weights()
cat_facts <- get_cat_facts(cat_weights)
cat_growth_plot_1 <- plot_cat_growth(cat_weights)
cat_weights_plot <- plot_cat_weights(cat_weights)
cat_growth_plot_2 <- plot_cat_growth_2(cat_weights)
extrapolated_growth_rates <- extrapolate_growth_rates(cat_weights, cat_facts)
# male cats
percentiles_adult_male <- adult_percentiles(male_centiles)
male_adult_distribution <- plot_distribution(percentiles_adult_male) + labs(
title = "Distribution of male adult cat weights")
# female cats
percentiles_adult_female <- adult_percentiles(female_centiles)
female_adult_distribution <- plot_distribution(percentiles_adult_female) + labs(
title = "Distribution of female adult cat weights")
# add out cats to these distributions
cat_weights_weeks <- convert_cat_weights(cat_weights)
satsuma_distribution <- plot_weight_for_my_cat("satsuma")
miso_distribution <- plot_weight_for_my_cat("miso")
percent_of_adult_plot <- plot_percent_of_adult()
satsuma_growth_chart <- growth_chart_for_my_cat("satsuma")
miso_growth_chart <- growth_chart_for_my_cat("miso")
# general tools
adult_weight_plot <- plot_weight_on_adult_distribution(8.2, "male")
general_weight_plot <- plot_weight_general(20, 3, "male")Show plots
And here are the results!
cat_growth_plot_1cat_growth_plot_2cat_weights_plotextrapolated_growth_ratessatsuma_growth_chartmiso_growth_chartmale_adult_distributionfemale_adult_distributionsatsuma_distributionmiso_distributionpercent_of_adult_plot