Task 1: Reflection

The data below is about civilian complaints allegations against the police officers of the New York Police Department.To answer further questions, a single complaint may include multiple allegations between multiple victims and multiple officers. For my question, I was curious to see the timeline of Allegations Over the Years by Allegation Type and the Officer Rank time of the incident. Based on the data, you can see that Police Officers were among the highest on all FADO types. FADO is an acronym to classify the four broad categories of police‐misconduct allegations. It wasn’t until 2020 that it dramatically dropped due to the BLM Movement and the George Floyd case.

Task 2: Visualizing time

library(tidyverse)
library(plotly)
library(dplyr)
library(readr)

# Load dataset
complaints_data <- read_csv("/Users/annapatrick/Downloads/archive-3/allegations_202007271729.csv")

# Define the specific ranks to include
selected_ranks <- c("Captain", "Detective", "Lieutenant", "Police Officer", "Sergeant")

# Filter and prepare the data
yearly_summary <- complaints_data %>%
  filter(!is.na(fado_type)) %>%
  filter(rank_incident %in% selected_ranks) %>%
  count(year_received, rank_incident, fado_type, name = "allegation_count") %>%
  mutate(allegation_count = allegation_count * 0.75)  

# Split the data by FADO type
fado_split <- split(yearly_summary, yearly_summary$fado_type)

# Create one Plotly trace per FADO type
fado_plots <- lapply(seq_along(fado_split), function(i) {
  df     <- fado_split[[i]]
  my_fado <- unique(df$fado_type)
  
  plot_ly(
    data      = df,
    x         = ~year_received,
    y         = ~allegation_count,
    color     = ~rank_incident,
    type      = "scatter",
    mode      = "lines+markers",
    hoverinfo = "text",
    text      = ~paste(
                  "Year:", year_received,
                  "<br>Allegations:", round(allegation_count,1),
                  "<br>Rank:", rank_incident,
                  "<br>FADO:", fado_type
                ),
    showlegend = (i == 1)   
  ) %>%
    layout(
      title = my_fado,
      xaxis = list(title = ""),
      yaxis = list(
        title      = my_fado,
        automargin = TRUE      
      )
    )
})

# Combine into a vertically stacked subplot
subplot(
  fado_plots,
  nrows    = length(fado_plots),
  shareX   = TRUE,
  shareY   = FALSE,
  titleY   = TRUE,
  margin   = 0.05,
  heights  = rep(1/length(fado_plots), length(fado_plots))
) %>%
  layout(
    title  = "Interactive Allegations Over Time by Rank and FADO Type",
    xaxis  = list(title = "Year"),
    legend = list(title = list(text = "Officer Rank")),
    margin = list(l = 80, t = 60, b = 50, r = 20)  
  )

Do the following:

  1. Load some time-related data

  2. Make a plot to show how that data changes over time.

  3. Explain why you chose to visualize the data the way you did: I chose this faceted line graph because it individually shows FADO with the officer rank clearly. I choose these colors because they are color blind friendly. I wanted to show the detailed comparisons among ranks without overlap with the lines. You can easily hover over an exact dot that you want. Plus each graph is clear and cohesive.