squirrel_census =
read_csv("data/clean_squirrel_2018.csv")
Squirrels are dynamic creatures with a secret language. In a bustling environment like New York City, these animals use unique signals to communicate with each other and us.
sounds_summary = data.frame(
Sound = c("Kuks", "Quaas", "Moans"),
Count = c(sum(squirrel_census[["kuks"]], na.rm = TRUE),
sum(squirrel_census[["quaas"]], na.rm = TRUE),
sum(squirrel_census[["moans"]], na.rm = TRUE))
)
plot_ly(data = sounds_summary, x = ~Sound, y = ~Count, color = ~Sound, type = 'bar', colors = RColorBrewer::brewer.pal(3, "Accent")) |>
layout(
xaxis = list(title = 'Sound Type'),
yaxis = list(title = 'Number of Squirrels'))
Of the three identified squirrel sounds, NYC squirrels most commonly
kuk
is the most common sound, and moans
are
rarely heard. To better understand the meaning of these sounds, let’s
take a look at the type of activity or interactions the squirrels who
made these sounds are engaged in.
# Summarizing sounds by interaction types
interaction_sounds <- squirrel_census |>
group_by(approaches, indifferent, runs_from) |>
summarise(Kuks = sum(kuks, na.rm = TRUE),
Quaas = sum(quaas, na.rm = TRUE),
Moans = sum(moans, na.rm = TRUE)) |>
pivot_longer(cols = c(Kuks, Quaas, Moans), names_to = "Sound", values_to = "Count")
# Creating a new column for interaction type
interaction_sounds[["interaction_type"]] <- case_when(
interaction_sounds[["approaches"]] == TRUE ~ "Approaches",
interaction_sounds[["indifferent"]] == TRUE ~ "Indifferent",
interaction_sounds[["runs_from"]] == TRUE ~ "Runs From",
TRUE ~ "Other"
)
# Creating sounds by human interaction plot
plot_ly(interaction_sounds, x = ~Sound, y = ~Count, color = ~interaction_type, type = 'bar', colors = RColorBrewer::brewer.pal(3, "Accent")) |>
layout(title = 'Distribution of Squirrel Sounds by Human Interaction',
xaxis = list(title = 'Sound Type'),
yaxis = list(title = 'Number of Squirrels'))
As this plot (right) shows, squirrels who kuk
are
frequently indifferent,
run from,
or exhibit
other
behavior when interacting with humans. Squirrels who
quaa
also are indifferent
or exhibit
other
behavior when approached by a human, and
run from
humans less frequently.
There is only one instance of a moan
, and this squirrel
ran from
a human. While this is an interesting data point,
there is not enough information to associate a moan
with
fear or distress. Without more data and a better understanding of what
other
behavior is, we cannot accurately determine what
these squirrel sounds mean.
Squirrels who kuk
and quaa
were very
frequently seen chasing
. In general, squirrels who
kuk
engaged in all activity types. Similarly, squirrels who
quaa
also participated in all activities, but with less
frequency. This is in line with our sounds distribution, as
quaa
is a rarer sound when compared to
kuks
.
Additionally, we see that squirrels who moan
were only
seen climbing
or foraging
. Overall, this
distribution gives us hints about the frequency of squirrel sounds and
their potential correspondence with different types of activity.
However, we do not have enough information to draw conclusions about
sound meanings and activity types.
# Reshaping data into a long format
long_data = squirrel_census |>
pivot_longer(cols = c(kuks, quaas, moans), names_to = "Sound", values_to = "Sound_Value") |>
pivot_longer(cols = c(running, chasing, climbing, eating, foraging), names_to = "Activity", values_to = "Activity_Value") |>
filter(Activity_Value == TRUE, Sound_Value == TRUE) |>
count(Activity, Sound) |>
rename(`Squirrels` = n)
# Creating a list to store plotly objects
plots_list = list()
# Looping through each activity to create individual plots
for(activity in unique(long_data[["Activity"]])) {
activity_data = long_data[long_data[["Activity"]] == activity, ]
p = plot_ly(activity_data, x = ~Sound, y = ~`Squirrels`, type = 'bar', name = activity) |>
layout(title = paste('Squirrel Sounds by Activity Type'))
plots_list[[activity]] = p
}
# Arranging the plots in a grid layout
subplot(plots_list, nrows = length(plots_list), shareX = TRUE, shareY = TRUE)
# Grouping sounds by age
sound_summary = squirrel_census |>
filter(age != "?") |>
group_by(age) |>
summarise(
Kuks = sum(kuks, na.rm = TRUE),
Quaas = sum(quaas, na.rm = TRUE),
Moans = sum(moans, na.rm = TRUE)
) |>
pivot_longer(cols = c(Kuks, Quaas, Moans), names_to = "Sound", values_to = "Count") |>
mutate(
perc_vocals = (Count/ sum(Count))*100
)
# Creating a bubble plot showing sound by squirrel age
plot_ly(data = sound_summary, x = ~age, y = ~perc_vocals, size = ~Count, type = 'scatter', mode = 'markers',
marker = list(sizemode = 'diameter', opacity = 0.5), color = ~Sound,
hoverinfo = 'text', text = ~paste(Sound, ': ', Count)) |>
layout(title = 'Squirrel Sounds by Age',
xaxis = list(title = 'Age'),
yaxis = list(title = 'Percent of Sound Type'))
Our plot shows us that adults were the most frequently identified
squirrel in our sample. For both adults and juveniles, kuks
were the most common sound. However, adults kuked
far more
than their juvenile counterparts. Again, there is not enough data to
conclude that adults are noisier than their juvenile counterparts, but
for our purposes, we are crowning kukking
adult squirrels
as the chattiest in New York City!