library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.3
## -- Attaching packages ------------------------------------------ tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.3 v dplyr 1.0.0
## v tidyr 1.1.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts --------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(dplyr)
library(leaflet)
t <- read.csv("https://raw.githubusercontent.com/jconno/Squirrels-of-Central-Park-10-2018/main/2018_Central_Park_Squirrel_Census_-_Squirrel_Data.csv")
#head(t)
names(t)
## [1] "X"
## [2] "Y"
## [3] "Unique.Squirrel.ID"
## [4] "Hectare"
## [5] "Shift"
## [6] "Date"
## [7] "Hectare.Squirrel.Number"
## [8] "Age"
## [9] "Primary.Fur.Color"
## [10] "Highlight.Fur.Color"
## [11] "Combination.of.Primary.and.Highlight.Color"
## [12] "Color.notes"
## [13] "Location"
## [14] "Above.Ground.Sighter.Measurement"
## [15] "Specific.Location"
## [16] "Running"
## [17] "Chasing"
## [18] "Climbing"
## [19] "Eating"
## [20] "Foraging"
## [21] "Other.Activities"
## [22] "Kuks"
## [23] "Quaas"
## [24] "Moans"
## [25] "Tail.flags"
## [26] "Tail.twitches"
## [27] "Approaches"
## [28] "Indifferent"
## [29] "Runs.from"
## [30] "Other.Interactions"
## [31] "Lat.Long"
# Location subset by activity (run, climb, eat)
location_activity <- t %>% select(X, Y, Unique.Squirrel.ID, Shift, Running, Climbing, Eating, Foraging)
Were there more squirrels spotted in Central Park during the morning or afternoon? What could explain this? > There were more squirrels seen during the afternoon. This could be due to the possibility that there are more parkgoers with food out and about.
AM_activity <- location_activity %>%
filter(Shift == "AM")
dim(AM_activity)
## [1] 1347 8
# There is a total of 1347 observations during the morning
PM_activity <- location_activity %>%
filter(Shift =="PM")
dim(PM_activity)
## [1] 1676 8
# There is a total of 1676 observations during the afternoon/evening
Were more squirrels spotted foraging or running during the morning or afternoon? > There were 34 more squirrels spotted running in the afternoon.
# Morning
table(AM_activity$Running, AM_activity$Foraging)
##
## false true
## false 500 520
## true 246 81
# Afternoon
table(PM_activity$Running, PM_activity$Foraging)
##
## false true
## false 562 711
## true 280 123
Creating a tagging variable for plotting the squirrels.
# Tag: concatenate unique ID and primary color columns
tag <- paste(t$Unique.Squirrel.ID, (","), t$Age, (","), t$Location, (","), t$Combination.of.Primary.and.Highlight.Color, (","), t$Date, t$Other.Activities, t$Other.Interactions)
leaflet() %>%
addTiles() %>%
addCircleMarkers(lng = location_activity$X, lat = location_activity$Y,
popup = tag, color = "blue", stroke = FALSE, fillOpacity = 0.4)
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.