Dog Breed Blog

Published

April 5, 2025

Required Packages

library(tidyverse)
library(tidytext)
library(ggthemes)
library(reactable)

Data Frames Used

nyc_dog_license <- read_csv('https://bcdanl.github.io/data/nyc_dog_license.csv')
nyc_zips_coord <- read_csv('https://bcdanl.github.io/data/nyc_zips_coord.csv')
nyc_zips_df <- read_csv('https://bcdanl.github.io/data/nyc_zips_df.csv')

Dog Breeds Across NYC Boroughs

top10_breeds <- nyc_dog_license |> count(breed_rc) |> arrange(-n) |> head(10)
top10_breeds$breed_rc
 [1] "Yorkshire Terrier"        "Labrador (or Crossbreed)"
 [3] "Shih Tzu"                 "Pit Bull (or Mix)"       
 [5] "Chihuahua"                "Maltese"                 
 [7] "Pomeranian"               "Havanese"                
 [9] "Shih Tzu Crossbreed"      "Beagle"                  
dog_df <- nyc_dog_license |> filter(!is.na(borough), breed_rc %in% top10_breeds$breed_rc) |> 
  count(borough, breed_rc) |> group_by(borough) |> arrange(-n)

dog_df$breed_rc <- factor(dog_df$breed_rc, levels = top10_breeds$breed_rc)

reactable(dog_df, columns = list(borough = colDef(name = "Borough"),
                                 breed_rc = colDef(name = "Breed"),
                                 n = colDef(name = "Count")))
ggplot(dog_df, aes(x = n, y = reorder_within(breed_rc, n, borough),
                   fill = breed_rc)) +
  geom_col(width = 1, color = "gray40", linewidth = 0.2) +
  facet_wrap(~borough, scales = "free_y", ncol = 1) +
  scale_y_reordered() +
  scale_fill_tableau() +
  labs(x = "Count",
       y = NULL,
       fill = "Breeds",
       title = "Dog Breeds Across NYC Boroughs") +
  guides(fill = guide_legend(keyheight = 2.3)) +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5, size = 18, face = "bold"),
        axis.text = element_text(size = 10),
        legend.text = element_text(size = 10),
        strip.text = element_text(size = 10, face = "bold"))