#In this report, I build on my Week 3 homework by looking at the NYC shooting dataset. I explore patterns in shootings by time of day and borough, clean up the data, and then use plots to highlight some key trends.

I pulled the latest 30,000 NYPD shooting incidents from NYC Open Data’s API and put them into R as a data frame for analysis.

shooting_data <- shooting_data %>% filter(!is.na(perp_race))
shooting_data <- shooting_data %>%
  mutate(boro = str_to_lower(boro),
         perp_race = str_to_lower(perp_race))

I got rid of missing rows, when race was not there, and I made boroughs and race lower case.

boro_counts <- shooting_data %>% count(boro)

I counted shootings per borough to compare the amount of shootings in each borough. The borough with the most shootings is brooklyn with 7404 incidents.

shooting_data <- shooting_data %>%
  mutate(
    occur_time = hms::as_hms(occur_time),
    hour = hour(occur_time),
    time_of_day = case_when(
      hour >= 6 & hour < 12 ~ "Morning",
      hour >= 12 & hour < 18 ~ "Afternoon",
      TRUE ~ "Night"
    )
  )

ggplot(shooting_data, aes(x = time_of_day, fill = time_of_day)) +
  geom_bar() +
  labs(title = "Shootings by Time of Day",
       x = "Time of Day",
       y = "Number of Shootings") +
  theme_minimal(base_size = 14) +
  scale_fill_brewer(palette = "Set2")

ggplot(shooting_data, aes(x = boro, fill = boro)) +
  geom_bar() +
  facet_wrap(~time_of_day) +
  labs(title = "Shootings by Borough and Time of Day",
       x = "Borough",
       y = "Number of Shootings") +
  theme_minimal(base_size = 14) +
  scale_fill_brewer(palette = "Set3")

kable(boro_counts)
boro n
bronx 6328
brooklyn 7404
manhattan 2953
queens 3069
staten island 680

I copied my codes from homework 3, where I analyzed the time of day that shootings were occuring, and then I plotted it. I then also plotted the amount of shootings by borough. I made a table of the borough counts.

NYC Open Data Shooting Incident Dataset ###This workflow makes it way easier to grab and clean big datasets. In my research I have to keep track of large datasets and I have to make sure my mentor understands what steps I am taking to clean the data we collect. The visualization helps me see the results in a clear way. My research is analzying people who believe in the Bad Apples Theory, and how that correlates with those who cause harm.