Week 13 : Pets In Seattle

TidyTuesday
2019
Published

March 27, 2019

library(readr)
library(tidyverse)
library(gganimate)
library(splitstackshape)
library(forcats)
library(ggthemr)

ggthemr("flat dark")
seattle_pets <- read_csv("seattle_pets.csv")
{{% tweet "1111090496372391937" %}}

GitHub Code

Yearly Change

Zipcode Counts Over the Years

p<-seattle_pets %>%
   cSplit("license_issue_date",sep = " ") %>%
   rename(Month =license_issue_date_1) %>%
   rename(Day = license_issue_date_2) %>%
   rename(Year = license_issue_date_3) %>%
   select(zip_code,Year) %>%
   group_by(Year) %>%
   count(zip_code) %>%
   remove_missing() %>%
   subset(Year >=2010) %>%
   top_n(25) %>%
ggplot(.,aes(x= fct_infreq(zip_code),y=n,fill=factor(Year)))+
  geom_col()+transition_time(Year)+ease_aes("linear") +
  coord_flip()+xlab("Zip code")+ylab(" Count")+
  labs(fill="Year")+
  scale_y_continuous(breaks=seq(0,3000,250),labels = seq(0,3000,250))+
  ggtitle("Zip Code Over the Years",subtitle="Year : {frame_time}")

animate(p,fps=1,nframes=7)

Species Counts Over the Years

seattle_pets %>%
   cSplit("license_issue_date",sep = " ") %>%
   rename(Month =license_issue_date_1) %>%
   rename(Day = license_issue_date_2) %>%
   rename(Year = license_issue_date_3) %>%
   select(species,Year) %>%
   subset(Year >=2016) %>%
   group_by(Year) %>%
   count(species) %>%
ggplot(.,aes(x= species,y=n,fill=factor(Year),label=n))+
  geom_col()+geom_text()+
  transition_states(Year,transition_length = 2,state_length = 2)+
  enter_fade()+exit_shrink()+ease_aes("back-in")+
  xlab("Species")+ylab("Count")+ labs(fill="Year")+
  scale_y_continuous(breaks=seq(0,23000,1000),labels=seq(0,23000,1000))+
  ggtitle("Species Over the Years",subtitle = "Year: {closest_state}")

Primary Breed Over the Years

p<-seattle_pets %>%
   cSplit("license_issue_date",sep = " ") %>%
   rename(Month =license_issue_date_1) %>%
   rename(Day = license_issue_date_2) %>%
   rename(Year = license_issue_date_3) %>%
   select(primary_breed,Year) %>%
   group_by(Year) %>%
   count(primary_breed) %>%
   remove_missing() %>%
   subset(Year >=2010) %>%
   top_n(15) %>%
ggplot(.,aes(x= str_wrap(primary_breed,20),y=n,label=n,fill=factor(Year)))+
  geom_col()+transition_time(Year)+ease_aes("linear") +
  coord_flip()+geom_text()+labs(fill="Year")+
  xlab("Primary Breed")+ylab("Count")+
  scale_y_continuous(breaks=seq(0,6000,500),labels=seq(0,6000,500))+
  ggtitle("Primary Breed Over the Years",subtitle = "Year : {frame_time}")

animate(p,fps=1,nframes=8)

Animals Name Over the Years

p<-seattle_pets %>%
   cSplit("license_issue_date",sep = " ") %>%
   rename(Month =license_issue_date_1) %>%
   rename(Day = license_issue_date_2) %>%
   rename(Year = license_issue_date_3) %>%
   select(animals_name,Year) %>%
   group_by(Year) %>%
   count(animals_name) %>%
   remove_missing() %>%
   subset(Year >=2010) %>%
   top_n(5) %>%
ggplot(.,aes(x= fct_infreq(animals_name),y=n,fill=factor(Year),label=n))+
  geom_col()+transition_time(Year)+ease_aes("linear") +
  coord_flip()+geom_text()+labs(fill="Year")+
  xlab("Animals Name")+ylab("Count")+
  scale_y_continuous(breaks = seq(0,275,25),labels=seq(0,275,25))+
  ggtitle("Animales N ame Over the Years",
          subtitle = "Year : {frame_time}")

animate(p,fps=1,nframes=8)

THANK YOU