Long Beach Animal Shelter

Author

Jo Hardin

Published

March 4, 2025

library(tidyverse) # ggplot, lubridate, dplyr, stringr, readr...
library(praise)

The Data

This week we’re exploring the Long Beach Animal Shelter Data!

The dataset comes from the City of Long Beach Animal Care Services via the {animalshelter} R package.

This dataset comprises of the intake and outcome record from Long Beach Animal Shelter.

longbeach <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-03-04/longbeach.csv')
longbeach |> 
  group_by(animal_type) |> 
  summarize(n())
# A tibble: 10 × 2
   animal_type `n()`
   <chr>       <int>
 1 amphibian       3
 2 bird         2075
 3 cat         14145
 4 dog          9768
 5 guinea pig    172
 6 livestock      10
 7 other        1332
 8 rabbit        526
 9 reptile       344
10 wild         1412
longbeach |> 
  ggplot(aes(x = animal_type, fill = intake_type)) + 
  geom_bar() + 
  theme(axis.text.x = element_text(angle = 45, hjust=1)) + 
  labs(x = "", y = "")

library(alluvial)
data <- longbeach |> 
  filter(animal_type %in% c("dog", "cat", "bird", "wild")) |> 
  mutate(animal = fct_rev(fct_infreq(animal_type)),
         intake = fct_rev(fct_infreq(fct_lump_n(intake_type, 5, other_level = "other"))),
         outcome = fct_rev(fct_infreq(fct_lump_n(outcome_type, 5, other_level = "other")))) |> 
  group_by(animal, intake, outcome) |> 
  summarize(n = n()) |> 
  drop_na()


alluvial(data |> select(-n),
         freq=data$n, border=NA, alpha = 0.5,
         col=case_when(data$animal == "cat" ~ "#FFA500",
                       data$animal == "dog" ~ "#8B4513",
                       data$animal == "bird" ~ "#FFD700",
                       TRUE ~ "#228B22"),
         cex=0.75,
         axis_labels = c("animal", "intake", "outcome"),
        hide = data$n < 150)

An alluvial plot with three strata: animal type, intake category, and outcome. We filtered to only consider cats, dogs, birds, and wild animals (the four groups that make up the majority of the animal types). Because dogs and cats are most prevalent, the most common intake type is stray. The cats and dogs both go to a variety of outcomes including adoption, rescue, euthanasia, transfer, and return to owner.

An alluvial plot to show how the type of animal goes through the shelter system, from intake to outcome. The vast majority of animals at the shelter are dogs and cats who are mostly stray animals.
praise()
[1] "You are superior!"