Load in Libraries

library(geojsonio)
library(leaflet)
library(gganimate)
library(rvest)
library(png)
library(tidyverse)
library(dplyr)
library(ggpubr)
library(stringr)

For our final project we were interested in looking at the NYC Squirrel Census collected by volunteers in October 2018. While the dataset is entitled “NYC Squirrel Census”, the data was geographically restricted to Central Park.

#Download Squirrel Census Dataset
nyc_squirrels <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-10-29/nyc_squirrels.csv")


dates <-nyc_squirrels %>%
  mutate(Month= substr(date, 1,2), Day=substr(date, 3,4), Year=substr(date,5,9))

  dates %>% 
  group_by(Day, shift) %>%
  count() %>%
  ggplot() +
  geom_col(aes(x=Day, y=n, fill=shift)) +
  scale_fill_brewer(palette = "Paired") +
  labs(x = "Day", y ="Number of Observations", fill='Shift') +
  ggtitle('Central Park Squirrel Data Collection Distribution (Oct. 2018)') +
  theme(plot.title = element_text(hjust = 0.5)) 

The data for the squirrel census was collected over a 14-day period starting October 6th, 2018. The majority of observations were recorded towards the beginning of the month and on October 13th and 14th. In addition to recording the date, time of day was also recorded for each of the observation (AM or PM). Recordings tend to be in the afternoon/evening. During fall months, squirrels are preparing for winter by eating and storing as much as much food as possible (FMR, 2021). This tends to happen in the early morning and later in the evening, with midday being the least active time for squirrel activity. Unfortunately, our temporal data is limited as we can’t identify what time exactly in the PM the data was collected, but it can be assumed that it was recorded prior to sunset.

#Clustered locations of squirrels
nyc_squirrels %>%
  leaflet() %>%
  addTiles() %>%
  addCircleMarkers(lng = ~long,
                   lat = ~lat, clusterOptions = markerClusterOptions())

Squirrels were predominately sighted in three areas of Central Park: the northern section (which includes the North Meadow and North Woods), areas in and around “The Lake”, and the southern section which includes Sheep Meadow and Central Park Drive. Zooming in closer, clusters of squirrels tend to appear in the wooded sections of the park and near the USS Maine Monument (SW corner of the park). Potential reasons for squirrel clustering could include areas where there are lots of trees (for nuts and sheltering purposes) or areas where humans and food vendors are prevalent (who doesn’t love free food). It is also important to note that they may be collection bias, as some portions of the park may have been surveyed more often throughout the survey period.

#What is the Age Distribution of Squirrels? 

squirrel_ages <- nyc_squirrels %>%
  mutate(age = na_if(age,'?'), n=1) %>%
  group_by(age) %>%
  summarize(age_sum = sum(n)) %>%
  ungroup() %>%
  mutate(total = sum(age_sum), dummy = '') %>%
  summarize(age, age_sum, total, dummy, pct_age = (age_sum/total)*100)

squirrel_ages[is.na(squirrel_ages)] <- "Unknown"


ggplot(squirrel_ages, aes(x=dummy, y= pct_age, fill=age)) +
  geom_col() +
  geom_text(aes(label=paste0(round(pct_age,digits=2), "%")), position = position_stack(vjust = 0.5)) +
  scale_fill_brewer(palette = "Paired") +
    theme_minimal(base_size = 16) +
    labs(x = "Total Population", y ="Percentage", fill='Age Group') +
   ggtitle('Central Park Squirrel Population by Age Group') +
    theme(plot.title = element_text(hjust = 0.5)) 

The majority of squirrels identified in Central Park were of adult-age (1+ year), with approximately 11% identified as juvenile based on size, fur color, and pigmentation. One may contribute an older population demographic to a lack of predation in urban areas and bounty of food sources (both in terms nuts and human food available in parks). Analysis of vocal calls (see below) supports this hypothesis, as quaas/moaning is associated with predation and was a less frequented sound than general squirrel communication sounds (kuks).

#What is the fur color of squirrels based on age? 
  nyc_squirrels %>%
  filter(age !='?') %>%
  mutate(n=1)%>%
  group_by(age) %>%
  ggplot() +
  geom_col(aes(y=n,x=age, fill=primary_fur_color), position="fill") +
  ggtitle('Demographics of Central Park Squirrels') +
  theme(plot.title = element_text(hjust = 0.5)) +
  labs( x='Age Group', y= 'Proportion') +
  labs(fill='Primary Fur Color') +
  scale_fill_manual(values = c("#000000", "#D2691E", "#D3D3D3", "white"))

#Mapping primary fur color

pal_coats <- colorFactor(c("#000000", "#D2691E", "#D3D3D3", "white"), domain = c("Black", "Cinnamon", "Grey", "NA"))

#Locations based on fur color
nyc_squirrels %>%
  filter(!is.na(primary_fur_color)) %>%
  leaflet() %>%
  addTiles() %>%
  addCircleMarkers(lng = ~long,
                   lat = ~lat, radius = 3, color = ~pal_coats(primary_fur_color), stroke = FALSE, fillOpacity = 0.5) %>%
  addLegend(position ="bottomright",pal = pal_coats, values = ~primary_fur_color)
## Warning in pal_coats(primary_fur_color): Some values were outside the color
## scale and will be treated as NA

## Warning in pal_coats(primary_fur_color): Some values were outside the color
## scale and will be treated as NA
## Warning in pal(v): Some values were outside the color scale and will be treated
## as NA

The predominant primary fur color for all Central Park squirrels is grey. This could be due to the fact that the grey squirrels are able to blend in best with the urban environment of NYC. A slightly greater proportion of juvenile squirrels have a primary fur color of cinnamon than adults. Juveniles tend to have brighter color coats than adults do (WildlifeOnline, 2021). Within Central Park, there is a slightly greater proportion of black squirrels than juveniles. Interestingly, black fur coats are due to recessive genes that cause abnormal pigmentation, and thus are only found in areas where the population is contained (such as Central Park).

Mapping the locations of Central Park squirrels based on fur color, clusters of black squirrels appear near the North Meadow Baseball fields and at the Southwest border of the park near the Central Park Zoo. Orange squirrels are generally congregated in the Southeastern portion of the park near Hechester Ballfields.

Data Source(s): https://www.wildlifeonline.me.uk/animals/group/squirrels https://untappedcities.com/2021/10/14/black-squirrels-nyc/

# Are squirrels facing predators in the park?
# Look at quaas and moans which are signs that squirrels are facing predators
pred <- nyc_squirrels %>%
  mutate(quaas = as.integer(nyc_squirrels$quaas),
         moans = as.integer(nyc_squirrels$moans),
         kuks = as.integer(nyc_squirrels$kuks),
         total = count(nyc_squirrels)) %>%
  mutate(moans_true = sum(moans),
         quaas_true = sum(quaas),
         kuks_true = sum(kuks)) %>%
  summarize(moans_true, quaas_true, total, kuks_true)


# Check to see counts of combos of quaas and moans
nyc_squirrels %>%
  group_by(quaas, moans) %>%
  count()
## # A tibble: 4 × 3
## # Groups:   quaas, moans [4]
##   quaas moans     n
##   <lgl> <lgl> <int>
## 1 FALSE FALSE  2971
## 2 FALSE TRUE      2
## 3 TRUE  FALSE    49
## 4 TRUE  TRUE      1
# Here we can see that there is 1 squirrel that was recorded both quaaing and moaning

predator <- pred[1, ]

p <- predator %>%
  mutate(quaas_moans_percent = ((quaas_true + moans_true)/n)*100,
         kuks_percent = (kuks_true/n)*100) %>%
  pivot_longer(c(quaas_moans_percent, kuks_percent), names_to = "vocal_pattern")


p %>%
  ggplot() +
  geom_col(fill = "#003b6f", aes(x = vocal_pattern, y = value)) +
  scale_x_discrete(labels= c("Kuks", "Quaas/Moans")) +
  geom_text(colour = "white", fontface = "bold", aes(x = vocal_pattern, y = value, label = paste0(round(value, digits = 2), "%")), position = position_stack(vjust = 0.5)) + 
  labs(x = "Vocal Call", 
       y = "Percentage",
       title = "Frequency of Vocal Patterns of NYC Squirrels")

We were curious about whether squirrels were coming across many predators while frolicking around Central Park. One indication of recognition of predators is the vocal patterns of squirrels. When a squirrel is heard “quaaing”, which is an elongated vocal communication, this can indicate the presence of a ground predator such as a dog. Additionally, squirrel “moaning” is a high-pitched vocal communication which can indicate the presence of an air predator such as a hawk. In the data there were very few (3 to be exact) observations of squirrels moaning while there were 50 squirrels caught quaaing. Meanwhile, kuks are a more generic form of squirrel communication which is a chirpy vocal sound used for a variety of reasons.

From this graph we can see that there is a very low percentage of squirrels in Central Park that are quaaing and moaning- indicating that there aren’t likely many squirrels who are facing predators (at least in October 2018 when this data was collected). This lack of predation is also reflected in the age distribution of squirrels where there are a significant number of adults being observed in the park.

#Show true activity count
activities <- nyc_squirrels %>%
  mutate(running = as.integer(nyc_squirrels$running),
         foraging = as.integer(nyc_squirrels$foraging),
         chasing = as.integer(nyc_squirrels$chasing),
         climbing = as.integer(nyc_squirrels$climbing),
         eating = as.integer(nyc_squirrels$eating)) %>%
  mutate(running_true = sum(running),
         foraging_true = sum(foraging),
         chasing_true = sum(chasing),
         climbing_true = sum(climbing),
         eating_true = sum(eating)) %>%
  summarize(running_true, foraging_true, chasing_true, climbing_true, eating_true)

activities <- activities[1, ]

activities <- pivot_longer(activities, c(running_true, foraging_true, chasing_true, climbing_true, eating_true), names_to = "activity")

activities_labels <- c("Foraging", "Eating", "Running", "Climbing", "Chasing")

activities %>%
  ggplot() +
  geom_col(fill = "#003b6f", aes(x = reorder(activity, -value), y = value)) + 
  scale_x_discrete(labels= activities_labels) +
  labs(x = "Activity", y = "Number of Squirrels", title = "What are NYC Squirrels Doing?")

Squirrels in Central Park were a hungry bunch- the top two activities that they were recorded doing was foraging and eating. Why was this so? We did some research and found that 2018 was a mast year for white oaks in Central Park (some even called it an ‘Acornucopia’), meaning that trees were releasing an abundance of nuts, creating a feeding frenzy for NYC squirrels! The least common activity of these five was chasing, perhaps because observers would need to see at least two squirrels together in order for this behavior to play out. Have you ever seen a squirrel sleeping? The people who collected this data did not- although they did happen to see and record a couple of dead squirrels…

Data Source: https://www.washingtonpost.com/local/call-it-an-acornucopia-oak-trees-in-our-area-are-producing-tons-of-seeds-this-year/2018/10/10/be339554-cc90-11e8-a3e6-44daa3d35ede_story.html

runs_from <- nyc_squirrels %>%
  group_by(runs_from) %>%
  count() %>%
  ggplot() + 
  geom_col(fill = "#003b6f", aes(x = runs_from, y = n))+
  labs(x = "Runs from", y = "")  +
  ylim(0, 3000)

indif <- nyc_squirrels %>%
  group_by(indifferent) %>%
  count() %>%
  ggplot() + 
  geom_col(fill = "#003b6f", aes(x = indifferent, y = n))+
  labs(x = "Indifferent", y = "") +
  ylim(0, 3000)

approaches <- nyc_squirrels %>%
  group_by(approaches) %>%
  count()  %>%
  ggplot() + 
  geom_col(fill = "#003b6f", aes(x = approaches, y = n)) +
  labs(x = "Approaches", y = "Count") +
  ylim(0, 3000)

ggarrange(approaches, runs_from, indif, ncol = 3, nrow = 1) %>%
  annotate_figure(top = "NYC Squirrel Behavior Towards Humans")

We were also curious about the relationship between squirrels and humans in New York. In Middlebury, squirrels run rampant, virtually unafraid of the college students they cross paths with as long as it means they can rummage around in the trash can outside of BiHall a few minutes longer or forage for nuts while students play frisbee on Battell Beach. In order to see whether the NYC squirrels were afraid of humans or not, we looked at their interactions and whether they approached, ran from or were indifferent towards humans. It’s worth pointing out that there were some observations in which the squirrel was somehow doing all three of these activities at once…whether that was a miscalculated entry or the squirrel did all three behaviors in a single interaction we are unsure. What we do know is that not many squirrels approached humans, more ran from humans, and about half of squirrels were indifferent from humans.