Homework 4

Working with Central Park Squirrel Census, 2018 Data

Main load

#install.packages("remotes")
#remotes::install_github("mine-cetinkaya-rundel/nycsquirrels18")
library(nycsquirrels18)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.4     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
?squirrels

Understanding the basics

First, I wanted to see the location of the squirrels to see if any specific location stood out

library(ggplot2)

ggplot(squirrels, aes(x=lat, y=long))+
  geom_point()

Here we can see there are quite a few squirrel sightings. We can also clearly see the outline of central park. We can compare this to central park and see where the squirrels are located. Note that when this is compared to an image of central park, the area that has very few squirrel sightings is a lake (which makes sense).

Here’s Graph 1

#THIS ONE
ggplot(squirrels, aes(x=lat, y=long, color=shift))+
  geom_point()+
  labs(color="Time of Day", x="Latitude",y="Longitude", title= "Location of Squirrel Sightings") +
  
  theme_classic()+
        theme(
        plot.title = element_text(size =12, face = "bold")
        
      )

Looking at different times

ggplot(squirrels, aes(x=lat, y=long))+
  geom_point() +
  facet_wrap(~shift)

From here, we can see the differences in where squirrels are seen in the morning and afternoon/evening. Overall, we can see more squirrel sightings in the evening. This makes sense because there are less hours in the morning when people are awake - on average, Americans wake up at 7:00 am and go to bed around 11:30 pm. This means there are generally 5 AM hours people are awake and could be in the park and 11 PM hours people could be awake in the park.

Colors of squirrels and danger

ggplot(squirrels, aes(x=lat, y=long))+
  geom_point() +
  facet_wrap(~primary_fur_color)

ggplot(squirrels, aes(x=lat, y=long, color=quaas))+
  geom_point() +
  facet_wrap(~runs_from)

Trying out facet wrap to see if there are more sightings on certain days

ggplot(squirrels, aes(x=lat, y=long, color=age))+
  geom_point() +
  facet_wrap(~date)

Types of coloring and their proportion to activities

ggplot(squirrels, aes(x=primary_fur_color, fill=running))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=chasing))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=climbing))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=eating))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=foraging))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=kuks))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=quaas))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=moans))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=tail_flags))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=tail_twitches))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=approaches))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=primary_fur_color, fill=indifferent))+
  geom_bar(position="fill") 

Here’s Graph 2

####BLACK SQUIRRELS ARE MORE SKITTISH? Also include this plot
ggplot(squirrels, aes(x=primary_fur_color, fill=runs_from))+
  geom_bar(position="fill")+
  labs(fill= "Runs away from people?", x="Primary Fur Color",y="Number of Squirrel Sightings", title= "How Skittish are Different Types of Squirrels?") +
  
  theme_classic()+
        theme(
        plot.title = element_text(size =12, face = "bold")
        
      )

Adult vs baby investigation

ggplot(squirrels, aes(x=age, fill=shift))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=age, fill=runs_from))+
  geom_bar(position="fill") 

ggplot(squirrels, aes(x=location, fill=age))+
  geom_bar(position="fill") 

Best time to see squirrels

#Number within the chronological sequence of squirrel sightings for a discrete sighting session.

#date used to be a function as was really hard to work with   
date_fixed<-squirrels%>%
  mutate(date = as.character(date))    
     

ggplot(date_fixed, aes(x=date, fill=shift))+
      geom_bar(position="dodge") +
       labs(fill= "Shift", x="Date",y="Number of Squirrel Sightings", title= "Sightings per day") +

     theme_classic()+
        theme(
        axis.text.x = element_text(color="black", size=10, angle=45),
        plot.title = element_text(size =12, face = "bold")
       
      )