── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.2 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.3 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.0
✔ purrr 1.0.2
── 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(janitor)
Attaching package: 'janitor'
The following objects are masked from 'package:stats':
chisq.test, fisher.test
library(sf)
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
library(mapview)
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
which was just loaded, will retire in October 2023.
Please refer to R-spatial evolution reports for details, especially
https://r-spatial.org/r/2023/05/15/evolution4.html.
It may be desirable to make the sf package available;
package maintainers should consider adding sf to Suggests:.
The sp package is now running under evolution status 2
(status 2 uses the sf package in place of rgdal)
library(lubridate)#read data from the data linkdata_url <-'https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-05-23/squirrel_data.csv'# Read in the datasquirrel_data <-read_csv(data_url)
Rows: 3023 Columns: 31
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (14): Unique Squirrel ID, Hectare, Shift, Age, Primary Fur Color, Highli...
dbl (4): X, Y, Date, Hectare Squirrel Number
lgl (13): Running, Chasing, Climbing, Eating, Foraging, Kuks, Quaas, Moans, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Extra credit
Data Cleaning
#Delet the useless columnsclean_data <- squirrel_data |>select(-c(9:12))
1. Mapview show the distribution of Squirrel
#Use sf package to create geom pointsquirrel_data_sf <-st_as_sf(x = clean_data,coords =c("X","Y"),crs =4326) |>st_transform(crs =2263)#Use mapview package to creat one mapviewmap <-mapview(squirrel_data_sf)#Show the red point as squireeal in mapviewmapview_squirrel_data <- squirrel_data_sf |>mapview(col.regions ="brown",legend = T,layer.name ="Squireea in Central Park",alpha =0.8 )mapview_squirrel_data
Description: The first visualization is an interactive map created with the mapview package in R, pinpointing the distribution of squirrel sightings in Central Park. Each brown point represents an individual sighting, providing a visual representation of squirrel population density and distribution patterns. This type of visualization is chosen because maps offer an intuitive way to spatially explore ecological data, allowing for immediate visual identification of hotspots and patterns that would be difficult to discern from raw numbers alone.
2. Line Graph of Squirrel Sightings Over Time
clean_data$Date <-mdy(clean_data$Date)#Plot the line chartggplot(clean_data, aes(x = Date, color ="oragne")) +geom_line(stat ="count") +xlab("Date") +ylab("Number of Sightings") +ggtitle("Squirrel Sightings Over Time")+theme_minimal()
Description: This line graph tracks the number of squirrel sightings over a series of dates. The purpose is to reveal any trends in sighting frequency over time, such as daily or seasonal changes. From the line chart, we could find that people see the most squiiel in Oct 12, and the data is more than 400. Line graphs are selected for time series data to depict trends and patterns clearly.
3. Bar Chart of Squirrel Activities
squirrel_data$Running <-as.numeric(squirrel_data$Running)squirrel_data$Chasing <-as.numeric(squirrel_data$Chasing)squirrel_data$Climbing <-as.numeric(squirrel_data$Climbing)squirrel_data$Eating <-as.numeric(squirrel_data$Eating)squirrel_data$Foraging <-as.numeric(squirrel_data$Foraging)activities <-colSums(squirrel_data[, c("Running", "Chasing", "Climbing", "Eating", "Foraging")])activities_df <-as.data.frame(activities)activities_df$Activity <-rownames(activities_df)rownames(activities_df) <-NULL# Create the bar plotggplot(activities_df, aes(x = Activity, y = activities, fill = Activity)) +geom_bar(stat ="identity") +xlab("Activity") +ylab("Count") +ggtitle("Count of Squirrel Activities") +theme_minimal() +theme(axis.text.x =element_text(angle =45, hjust =1))
Description: The bar chart measures the frequency of different squirrel behaviors. By presenting each activity as a bar, it becomes easy to compare how often each behavior was observed. From the bar chart, we could found that the most frequency activity us foraging. Bar charts are effective for comparing quantities across categories.
`summarise()` has grouped output by 'Shift'. You can override using the
`.groups` argument.
# Plot the Heat Mapggplot(sightings_summary, aes(x = Location, y = Shift, fill = number_of_sightings)) +geom_tile() +scale_fill_gradient(low ="blue", high ="red") +xlab("Location in Central Park") +ylab("Shift") +ggtitle("Heatmap of Squirrel Sightings by Shift and Location") +theme(axis.text.x =element_text(angle =45, hjust =1))
Description: This heatmap displays the intensity of squirrel sightings according to the time of day and the general location (e.g., ground or above ground).The color intensity in each cell represents the number of sightings: the darker the color, the higher the number of sightings. Purple indicates fewer sightings, while red shows more, and blue the most, according to the color scale on the right. From the heatmap, we could find that people are most frequency see the squirrel in the ground plane in Afternoon. Heatmaps are useful for comparing categorical data against each other, allowing one to quickly discern which combinations of categories have the highest occurrences.