library(tidyverse) # ggplot, lubridate, dplyr, stringr, readr...
library(praise)
Long Beach Animal Shelter
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.
<- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-03-04/longbeach.csv') longbeach
|>
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)
<- longbeach |>
data 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",
$animal == "dog" ~ "#8B4513",
data$animal == "bird" ~ "#FFD700",
dataTRUE ~ "#228B22"),
cex=0.75,
axis_labels = c("animal", "intake", "outcome"),
hide = data$n < 150)
praise()
[1] "You are superior!"