Noise Complaints Visualization

Libraries Required

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── 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(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
library(lubridate)
library(dplyr)

Load the data

noise_data <- read_csv("311_service_data.csv")
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
  dat <- vroom(...)
  problems(dat)
Rows: 740913 Columns: 41
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (24): Created Date, Closed Date, Agency, Agency Name, Complaint Type, De...
dbl  (7): Unique Key, Incident Zip, BBL, X Coordinate (State Plane), Y Coord...
lgl (10): Location Type, Landmark, Due Date, Vehicle Type, Taxi Company Boro...

ℹ 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.

noise data

noise_data <- noise_data %>%
  mutate(
    created_datetime = mdy_hms(`Created Date`),
    day_of_week = wday(created_datetime, label = TRUE, abbr = TRUE)
  )

borough count

borough_counts <- noise_data %>%
  filter(!is.na(Borough)) %>%
  group_by(Borough) %>%
  summarise(complaint_count = n()) %>%
  ungroup()

borough bar chart

p_borough <- ggplot(borough_counts, aes(x = fct_reorder(Borough, complaint_count), y = complaint_count)) +
  geom_col(fill = "#D55E00", color = "black") +
  scale_y_continuous(labels = scales::label_number(scale = 1e-3, suffix = "K")) +
  labs(
    title = "NYC Noise Complaints by Borough",
    x = "Borough",
    y = "Number of Complaints"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

ggplotly(p_borough)

day of the week chart

p_day <- ggplot(noise_data, aes(x = day_of_week)) +
  geom_bar(fill = "#4C72B0", color = "black") +
  labs(
    title = "NYC Noise Complaints by Day of the Week",
    x = "Day of the Week",
    y = "Number of Complaints"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

ggplotly(p_day)

noise descriptor chart