## ggplot2 dplyr lubridate reshape2 magrittr
## TRUE TRUE TRUE TRUE TRUE
## stringi RColorBrewer tidyr ggthemes scales
## TRUE TRUE TRUE TRUE TRUE
## RSocrata gridExtra extrafont
## TRUE TRUE TRUE
Uses the City of Austin’s data service http://data.austintexas.gov to pull Austin Animal Center’s “outcomes” of all cats and dogs leaving the city shelter (link)
# Austin Animal Center FY15 Outcomes *Updated Hourly*
Animal.Outcomes <- RSocrata::read.socrata("https://data.austintexas.gov/resource/fb53-k8de.csv")
Outcomes <- Animal.Outcomes
Outcomes$Breed = gsub(" Mix", "", Outcomes$Breed)
Outcomes <- separate(Outcomes, col = Breed, into = c("Breed.Primary", "Breed.Secondary"), sep = "/", remove = T, fill = "right")
Outcomes$Breed.Secondary[is.na(Outcomes$Breed.Secondary)] <- Outcomes$Breed.Primary[is.na(Outcomes$Breed.Secondary)]
# Blank string become NA
Outcomes[Outcomes==""] <- NA
# Transform results
Outcomes <- Outcomes %>%
# Read in date column as a date
mutate(Outcome.Date = mdy(Outcome.Date)) %>%
# Only select cats and dogs
filter(Animal.Type %in% c("Cat", "Dog")) %>%
# Clean up the List of breeds and outcomes
mutate(Outcome.Type = ifelse(Outcome.Type %in% c("Adoption", "Euthanasia", "Return to Owner", "Transfer"),
Outcome.Type, "Other"))
# Splits the "Sex.upon.Outcome" column into two columns, sex and spay/neuter
Outcomes <- SN_Sex_replacer(Outcomes)
# If a breed has less that 'cutoff' instances, then it becomes known as "other"
# Outcomes <- simple_breed(Outcomes, cutoff = 10)
# Creates the 'Age' vector in days
Outcomes <- separate(Outcomes, col = Age.upon.Outcome, into = c("Age.Num", "Age.Unit"), sep = " ", remove = T, fill = "right")
Outcomes$Age <- ifelse(Outcomes$Age.Unit=="years" | Outcomes$Age.Unit=="year", 365, 0)
Outcomes$Age <- ifelse(Outcomes$Age.Unit=="months" | Outcomes$Age.Unit=="month", 30, Outcomes$Age)
Outcomes$Age <- ifelse(Outcomes$Age.Unit=="weeks" | Outcomes$Age.Unit=="week", 7, Outcomes$Age)
Outcomes$Age <- ifelse(Outcomes$Age.Unit=="days" | Outcomes$Age.Unit=="day", 1, Outcomes$Age)
Outcomes$Age <- Outcomes$Age * as.numeric(Outcomes$Age.Num)
# Make these columns factors
Outcomes$Outcome.Type = as.factor(Outcomes$Outcome.Type)
Outcomes$Outcome.Subtype = as.factor(Outcomes$Outcome.Subtype )
Outcomes$Animal.Type = as.factor(Outcomes$Animal.Type )
Outcomes$Animal.ID = as.factor(Outcomes$Animal.ID)
Figure 01: Histogram of each
Outcome Type, grouped bySex
Figure 02: Histogram of each
Outcome Type, grouped bySpecies
Figure 03: Boxplots (top) and Violin plots (bottom) of each
Age&Species, grouped byOutcome Type
The figure has three parts with different sclaes on the y-axis:
Age in yearsAge in monthsAge in weeksAll three figures represnet the same dataset, so don’t be confused!
Figure 04: Frequency of
Outcome Typeover the time period of one year
Figure 05(a): Heatmap representing the total count of cats with each
Outcome Typeon a month by month interval
Figure 05(b): Heatmap representing the density of eachOutcome Typein respect to the month (cats only)
Figure 05(c): Heatmap representing the total count of dogs with each
Outcome Typeon a month by month interval
Figure 05(d): Heatmap representing the density of eachOutcome Subtypein respect to the month (dogs only). Note that the density calculation is grouped byOutcome SubtypenotOutcome Typelike Figure 05(c)
Figure 06(a): This figure illustrates the number of cats that exit AAC by
Breed. Each bar is further broken down by color representing the number of cats with eachOutcome Type
Figure 06(b): A similar view as Figure 06(a), but instead of stacking theOutcome Types, we facet by the types
Figure 06(c): This figure demonstrates the relitive distribution ofOutcome Typeby measuring the density for eachBreed
Figure 07(a): This figure illustrates the number of dogs that exit AAC by
Breed. Each bar is further broken down by color representing the number of dogs with eachOutcome Type
Figure 07(b): A similar view as Figure 07(a), but instead of stacking theOutcome Type, we facet by the types
Figure 07(c): This figure demonstrates the relitive distribution ofOutcome Typeby measuring the density for eachBreed
Figure 08(a): Heatmap of the count of cats euthanized, broken down by
BreedandReason. The figure is also annotated with a number representing the percentage of that breed with each particularOutcome Subtype(i.e. reason for euthanasia) relative to the total number of animals of that breed who leave the shelter
Figure 08(b): Heatmap of the count of dogs euthanized, broken down by
BreedandReason. The figure is also annotated with a number representing the percentage of that breed with each particularOutcome Subtype(i.e. reason for euthanasia) relative to the total number of animals of that breed who leave the shelter
Hunter Ratliff
Email: hunter.ratliff@austinpetsalive.org
Twitter: @HunterRatliff1
Copyright (C) 2015 Hunter Ratliff
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.