About the project

This project analyzes animal intake data from Austin Animal Center since 2016. The data was imported from Austin’s Open Data Portal, and cleaned separately by me.

Setup

Import the following libraries to help analyze our data: tidyverse, lubridate, scales, plotly, and clipr

library(tidyverse)
library(lubridate)
library(scales)
library(plotly)
library(clipr)

Import data

Import the Austin Animal Center intakes dataset we cleaned in 01-import

intakes <- read_rds("data-processed/01-intakes.rds")

# peek at the data
intakes %>% glimpse
## Rows: 90,299
## Columns: 14
## $ intake_date      <date> 2019-01-03, 2016-04-14, 2017-02-18, 2019-04-16, 2020…
## $ yr               <dbl> 2019, 2016, 2017, 2019, 2020, 2018, 2016, 2017, 2019,…
## $ mo               <ord> Jan, Apr, Feb, Apr, Jun, Jun, Aug, Oct, Mar, Feb, Nov…
## $ yr_mo            <chr> "2019-01", "2016-04", "2017-02", "2019-04", "2020-06"…
## $ animal_id        <chr> "A786884", "A724273", "A743852", "A635072", "A818975"…
## $ name             <chr> "*Brock", "Runster", "Odin", "Beowulf", NA, NA, "*Cas…
## $ found_location   <chr> "2501 Magin Meadow Dr in Austin (TX)", "2818 Palomino…
## $ intake_type      <chr> "Stray", "Stray", "Owner Surrender", "Public Assist",…
## $ intake_condition <chr> "Normal", "Normal", "Normal", "Normal", "Normal", "In…
## $ animal_type      <chr> "Dog", "Dog", "Dog", "Dog", "Cat", "Cat", "Cat", "Dog…
## $ sex_upon_intake  <chr> "Neutered Male", "Intact Male", "Neutered Male", "Neu…
## $ age_upon_intake  <chr> "2 years", "11 months", "2 years", "6 years", "4 week…
## $ breed            <chr> "Beagle Mix", "Basenji Mix", "Labrador Retriever Mix"…
## $ color            <chr> "Tricolor", "Sable/White", "Chocolate", "Black", "Cre…

Intakes by year

Answer the following question:

  • Are animal intakes increasing or decreasing each year since 2016? Plot a column chart of intakes by year. Don’t include 2021 since it is not a full year.

Summarise data

intakes_yr_data <- intakes %>% 
  filter(
    yr < "2021"
  ) %>% 
  count(yr, name= "count_animals")

intakes_yr_data 

Plot data

ggplot(intakes_yr_data, aes(x = yr, y = count_animals)) + 
  geom_col(aes(fill = yr)) +
  geom_text(aes(label = comma(count_animals)), vjust = 2, color = "white") +
  labs(
    title = "Intakes By Year",
    subtitle = "Total animals taken in by Austin Animal Center per year since 2016",
    caption="Source: austintexas.gov",
    x = "Year",
    y = "Total animals"
  ) +
  scale_y_continuous(labels = comma)

Intakes by month

Answer the following question:

  • Are there seasonal monthly trends in overall animal intakes?

Summarise the data

Use count to find monthly intakes by year

intakes_yrmo <- intakes %>% 
  count(yr_mo, name = "count_animals")

intakes_yrmo

Plot intakes by yr/mo

Look at the overall trends of intakes broken down by month to understand where we should dig in more.

ggplot(intakes_yrmo, aes(x = yr_mo, y = count_animals)) +
  geom_line(group = 1) +# tell ggplot to only plot the single line
  theme(axis.text.x = element_text(angle = 90)) # flips the axis name

Intakes by month, split by year

Use month and year columns to show trends in intakes by year

Summarise the data

Use count to intakes by month and year intakes by year

mo_yr_data <- intakes %>% 
  count(mo, yr, name = "count_animals") # count animal intakes by month, year

mo_yr_data

Plot

ggplot(mo_yr_data, aes(x = mo, y = count_animals)) + # set x and y axis
  geom_line(aes(group = yr, color = as.character(yr))) + # split lines and set colors
  labs(
    title = "Intake Trends By Month",
    subtitle = "Amount of animals taken in monthly by year",
    x = "Month",
    y = "Animal Count",
    color = "Year", # fix the title for the legend
    caption = "Source: austintexas.gov"
  )

Types by month

Answer the following question (using only full-year data)

  • Do certain types of animals drive seasonal trends?

Recode data

Create an “other” group for animals other than cats and dogs, filter data for complete years

intake_types <- intakes %>% 
  filter(yr < 2021) %>% 
  mutate(
    animal_type = recode(
      animal_type, # column
      "Bird" = "Other", # Values to rename
      "Livestock" = "Other"
      )
  )

intake_types %>% 
  count(animal_type)

Summarise data

Use count to find amount of animals taken in by month

type_mo_count <- intake_types %>% 
  count(mo, animal_type, name = "count_animals") # count animal types per month

# peek at the data
type_mo_count

Plot animal types by month

ggplot(type_mo_count, aes(x = mo, y = count_animals)) +
geom_line(aes(group = animal_type, color = animal_type)) + # split by animal type
  labs(
    title = "Monthly Trends In Animal Types",
    subtitle = "Types of animals taken in by type each month since 2016",
    x = "Month",
    y = "Animal Count",
    color = "Type", # fix the title for the legend
    caption = "Source: austintexas.gov"
  )