I have decided to look at the dataset for the dogs up for adoption through PetFinder and see which specific breeds are up for adoption the most and least depending on which state they are in. I will be focusing only on two of the main West Coast states(Oregon, Washington) to focus my work more. I think this will be interesting to see because it will give insight into what dog breeds are most and least popular in certain areas in the West Coast.
I plan to address this problem statement by first loading in the three datasets provided and reviewing them all to gain a better knowledge of the contents and deciding what will be of use to me. The data will then be cleaned up to address any potential missing values or other concerns with the data. Then, using the data that will help me in gaining insight into what I’m interested in, I am going to analyze those specific variables and also create some visualizations that better represent and explain the insights that I find.
I believe that this information can assist consumers in better providing resources to breeds that require more help in becoming adopted, as well as maybe relocating particular breeds to areas where they are more likely to be adopted.
For this project, these are the packages that I will be loading in order to clean, analyze, and visualize the data.
library(tidyverse) #Used for tidying up the data
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr) #Used for manipulating the data
library(ggplot2) #Used for visualizations
library(knitr) #Formatting table
library(treemap) #Creating treemap visualizations
Since my focus only requires analyzing dog_descriptions that is the only data frame I will be cleaning and analyzing for this project and this data frame contains 35 variables. NA is used to record missing variables. The description variable in the dog_descriptions dataset provides detailed, unique, and individualized information about the dogs. In dog_descriptions there is a variable for species and another variable type that is sharing the same information. In dog_descriptions as well the photo, color_tertiary, and declawed columns are almost completely NA.
setwd("/Users/mjodice/Downloads/Data Management/FinalProject/dogs")
dog_descriptions_df <- read.csv("dog_descriptions.csv")
#I am going to get rid of the type column because it provides repeated information that the species variable has already provided.
#I am getting rid of the photo column because it is almost completely NA anyways and also you can see a photo of the dog when you click on the link in the url column.
#I am getting rid of the declawed column because every response is NA outside of 1 so the information is not useful.
#I am getting rid of color_tertiary because it has mostly NAs and with the primary and secondary color columns I don't think that information would be useful.
#I am getting rid of the species column because it is already known that we are talking about dogs
#The description and URL variables are not relevant so those will be removed as well.
colSums(is.na(dog_descriptions_df))
## id org_id url species breed_primary
## 0 0 0 0 0
## breed_secondary breed_mixed breed_unknown color_primary color_secondary
## 37359 0 0 32046 46121
## color_tertiary age sex size coat
## 56963 0 0 0 30995
## fixed house_trained declawed special_needs shots_current
## 0 0 58180 0 0
## env_children env_dogs env_cats name tags
## 30153 23511 38828 0 53078
## photo status posted contact_city contact_state
## 58147 0 0 0 0
## contact_zip contact_country stateQ accessed type
## 12 0 0 33 640
## description
## 8705
dd_clean_df <- dog_descriptions_df %>%
select(-type, -photo, -declawed, -color_tertiary, -species, -url, -description)
#For dog_descriptions I'm changing the age data type from character to integer to be more appropriate and changing the sex and size data types to factor since they are considered to be categorical data.
#The variables I'm focusing on is the the breed column which give us information on the breed of each dog and contact_state which gives us which state each dog is from.
#I am also selecting only the states that I will be working with for this project.
dd_clean_df <- dd_clean_df %>%
mutate(age = as.integer(age), sex = as.factor(sex), size = as.factor(size)) %>%
select(id, breed_primary, sex, house_trained, contact_state) %>%
filter(contact_state %in% c('OR', 'WA'))
#Here are the first 10 rows of the cleaned dataset.
knitr::kable(head(dd_clean_df, 10))
| id | breed_primary | sex | house_trained | contact_state |
|---|---|---|---|---|
| 46038222 | Labrador Retriever | Female | FALSE | OR |
| 46037959 | Australian Cattle Dog / Blue Heeler | Male | FALSE | OR |
| 46036062 | Mixed Breed | Male | FALSE | OR |
| 46035982 | Mixed Breed | Female | FALSE | OR |
| 46035903 | Mixed Breed | Female | FALSE | OR |
| 46026268 | Labrador Retriever | Male | FALSE | OR |
| 46026254 | Mixed Breed | Female | FALSE | OR |
| 46026211 | Mixed Breed | Female | FALSE | OR |
| 46026103 | Australian Shepherd | Male | FALSE | OR |
| 46020354 | Retriever | Female | TRUE | OR |
Firstly, I’m looking at highest and lowest frequencies of each breed depending on whether they are in Washington or Oregon. I am only looking at the 10 most and least commonly seen breeds to organize the data better since there are too many breeds to include all of them.
#Most frequent breeds
max_frequency_breeds <- dd_clean_df %>%
group_by(contact_state, breed_primary) %>%
summarise(count = n()) %>%
arrange(contact_state, desc(count)) %>%
group_by(contact_state) %>%
slice(1:10)
## `summarise()` has grouped output by 'contact_state'. You can override using the
## `.groups` argument.
treemap(
max_frequency_breeds %>%
filter(contact_state == 'OR'),
index = c("contact_state", "breed_primary"),
vSize = "count",
palette = "Blues",
title = "10 Most Common Breeds for Adoption in Oregon"
)
treemap(
max_frequency_breeds %>%
filter(contact_state == 'WA'),
index = c("contact_state", "breed_primary"),
vSize = "count",
palette = "Blues",
title = "10 Most Common Breeds for Adoption in Washington"
)
#Least frequent breeds
min_frequency_breeds <- dd_clean_df %>%
group_by(contact_state, breed_primary) %>%
summarise(count = n()) %>%
arrange(contact_state, count) %>%
group_by(contact_state) %>%
slice(1:10)
## `summarise()` has grouped output by 'contact_state'. You can override using the
## `.groups` argument.
treemap(
min_frequency_breeds %>%
filter(contact_state == 'OR'),
index = c("contact_state", "breed_primary"),
vSize = "count",
palette = "Blues",
title = "10 Least Common Breeds for Adoption in Oregon"
)
treemap(
min_frequency_breeds %>%
filter(contact_state == 'WA'),
index = c("contact_state", "breed_primary"),
vSize = "count",
palette = "Blues",
title = "10 Least Common Breeds for Adoption in Washington"
)
Next, I wanted to take a look at the sex of these breeds to see if that could be potentially playing a role in their ability to get adopted. For this, I am only going to be looking at the top 5 breeds.
top_gender_breeds <- dd_clean_df %>%
group_by(contact_state, breed_primary, sex) %>%
summarise(count = n()) %>%
arrange(contact_state, desc(count)) %>%
group_by(contact_state) %>%
top_n(n = 10, wt = count)
## `summarise()` has grouped output by 'contact_state', 'breed_primary'. You can
## override using the `.groups` argument.
ggplot(top_gender_breeds, aes(x = breed_primary, y = count, fill = sex,
na.rm = TRUE)) +
geom_col() +
facet_wrap(~contact_state, scales = 'free') +
labs(title = "Gender of the Top 5 Breeds Up for Adoption in Washington
and Oregon",
x = "Breed",
y = "Count") +
scale_fill_manual(values = c('lightblue', 'lightpink')) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
Lastly, I want to look at whether they are house trained or not and if that potentially plays a role in their ability to be adopted. For this, I am only looking at the top 4 most common breeds up for adoption and their house_trained status in the two states.
wa_house_trained <- dd_clean_df %>%
group_by(contact_state, breed_primary, house_trained) %>%
filter(contact_state == 'WA') %>%
summarise(count = n()) %>%
arrange(contact_state, desc(count)) %>%
group_by(contact_state, house_trained) %>%
top_n(n = 3, wt = count)
## `summarise()` has grouped output by 'contact_state', 'breed_primary'. You can
## override using the `.groups` argument.
ggplot(wa_house_trained, aes(x = breed_primary, y = count, fill = house_trained)) +
geom_col(width = 0.3) +
facet_wrap(~contact_state, scales = 'free') +
labs(title = "Most Common Breeds Up for Adoption and their House Trained Status in Washington",
x = "Breed",
y = "Count",
fill = "House Trained") +
scale_fill_manual(values = c('darkred', 'darkgreen')) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
or_house_trained <- dd_clean_df %>%
group_by(contact_state, breed_primary, house_trained) %>%
filter(contact_state == 'OR') %>%
summarise(count = n()) %>%
arrange(contact_state, desc(count)) %>%
group_by(contact_state, house_trained) %>%
top_n(n = 3, wt = count)
## `summarise()` has grouped output by 'contact_state', 'breed_primary'. You can
## override using the `.groups` argument.
ggplot(or_house_trained, aes(x = breed_primary, y = count, fill = house_trained)) +
geom_col(width = 0.3) +
facet_wrap(~contact_state, scales = 'free') +
labs(title = "Most Common Breeds Up for Adoption and their House Trained Status in Oregon",
x = "Breed",
y = "Count",
fill = "House Trained") +
scale_fill_manual(values = c('darkred', 'darkgreen')) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
The problem statement that I addressed was which dog breeds were most and least commonly up for adoption depending on which state they were in with my focus being on two West Coast states(Washington and Oregon). By seeing where the breeds are the most and the least popular we have the potential to find them homes through relocation and sending them somewhere they would have a higher chance of being adopted.
I was addressing this issue by cleaning up the data and picking only the variables that were important to what I was trying to analyze. Because there were too many dog breeds to graph them all, I decided to simply look at the top dog breeds that were most regularly and least frequently placed up for adoption.
From the treemaps, we can observe that many of the same breeds are commonly available for adoption in both of these states, which is not surprising given their proximity. However, when we specifically look at the Boxer and Chihuahua breeds, we can see that they are less frequently up for adoption in Oregon but are among the most commonly available breeds up for adoption in Washington so they have the potential for being relocated. When it came to gender, there didn’t seem to be any significant difference or preference for female or male dogs in Oregon but in Washington there shows to be many more female dogs up for adoption than males. As you can see from the house trained bar chart for Oregon, Border Collies had the highest frequency of not being house trained, and when you look back at the treemap for the most common breeds up for adoption in Oregon, Border Collies were number one as well, so being house trained appears to play a role in them being up for adoption while in Washington, Labrador Retrievers were one of the most commonly put up for adoption but they were more often than not house trained so the extent that being house trained plays in their likelihood of being adopted seems to be a bit more inconclusive.
The implications are that, while they may be able to gather insights in order to possibly relocate the animals to a state where they have a better chance of finding homes, it is completely another to actually obtain the resources to do so, which they must then navigate through themselves to see if it is something that they could actually put into action.
The limits of my analysis are that it is not all-inclusive because I only focused on two of the states and just on the top number of breeds for my visualizations. I also didn’t get into any of the other possible variables that could be at work, such as the dogs’ ages or whether they got along with children or not.