Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fryenycc committed Sep 15, 2023
2 parents 357d066 + e9e1e72 commit 9325c2b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ od_dl_sub <- unique(od_dl_sub)

```{r}
# ---- Street cleanliness over time: plot
ggplot(od_dl_sub[od_dl_sub$date_ym < "2023-09-01"], aes(x= date_ym, y=n_comp, color=complaint_type), group=complaint_type) + geom_line() +
ggplot(od_dl_sub, aes(x= date_ym, y=n_comp, color=complaint_type), group=complaint_type) + geom_line() +
theme_bw() + labs(x="Date", y="Number of Complaints", title="311 Data on Street Cleanliness Complaints Over Time",
subtitle="Jan 2018 - July 2023", colour="Complaint type") + theme_nycc()
# ggsave(filename = "clean_over_time.png", path = "visuals", width=10, height=7)
Expand All @@ -100,6 +100,7 @@ clean_over_time_df <- dcast(melt(as.data.table(od_dl_sub[od_dl_sub$date_ym < "20
id.vars = c("complaint_type", "date_ym")),
date_ym + variable ~ complaint_type, value.var = "value") %>%
select(date_ym, `Dirty Conditions`, `Missed Collection`, `Sanitation Condition`)
clean_over_time_df
# write.csv(clean_over_time_df, "data/output/clean_over_time.csv")
```

Expand All @@ -108,6 +109,7 @@ clean_over_time_df <- dcast(melt(as.data.table(od_dl_sub[od_dl_sub$date_ym < "20
clean_by_cd_df <- od_dl[complaint_type %in% c("Dirty Conditions", "Missed Collection", "Sanitation Condition")] %>%
group_by(community_board) %>%
summarise(count=n())
clean_by_cd_df
# write.csv(clean_by_cd_df, "data/output/clean_by_comm.csv")
```

Expand All @@ -122,6 +124,7 @@ dsny_311_id <- dsny_311[dsny_311$complaint_type == "Illegal Dumping",]
```{r}
# ---- Illegal dumping over time: table
id_over_time_df <- dsny_311_id %>% group_by(date_ym) %>% summarise(n_comp=n())
id_over_time_df
# write.csv(id_over_time_df, "data/output/id_over_time.csv")
```

Expand All @@ -134,6 +137,7 @@ ggplot(id_over_time_df[id_over_time_df$date_ym < "2023-09-01",], aes(x= date_ym,
```{r}
# ---- Illegal dumping by community district: table
id_by_cd_df <- dsny_311_id %>% group_by(community_board) %>% summarise(n_comp=n())
id_by_cd_df
# write.csv(id_by_cd_df, "data/output/id_by_comm.csv")
```

Expand All @@ -147,6 +151,7 @@ dsny_311_dv <- dsny_311[dsny_311$complaint_type == "Derelict Vehicles",]
```{r}
# ---- Derelict vehicles over time: table
dv_over_time_df <- dsny_311_dv %>% group_by(date_ym) %>% summarise(n_comp=n())
dv_over_time_df
# write.csv(dv_over_time_df, "data/output/dv_over_time.csv")
```

Expand All @@ -159,6 +164,7 @@ ggplot(dv_over_time_df[dv_over_time_df$date_ym < "2023-09-01",], aes(x= date_ym,
```{r}
# ---- Derelict vehicles by community district: table
dv_by_cd_df <- dsny_311_dv %>% group_by(community_board) %>% summarise(n_comp=n())
dv_by_cd_df
# write.csv(dv_over_time_df, "data/output/dv_by_comm.csv")
```

Expand Down Expand Up @@ -204,7 +210,7 @@ cb_by_cd_df <- dep_311_cb %>% group_by(community_board) %>% summarise(n_comp=n()

```{r}
dep_311_grease <- dep_311[grepl("grease", dep_311$descriptor, ignore.case = TRUE),]
# dep_311_grease
dep_311_grease
# write.csv(dep_311_grease, "data/output/all_grease_data.csv")
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@ library(tidyverse)
library(htmltools)
library(ggiraph)
library(zoo)
library(readr)
library(data.table)
library(councildown)

# run 01_311_inital_request.Rmd first
# accompanying interactive plots to 01_311_initial_request.Rmd
# you don't have to run the first file if you just want the interactive plots

dsny_311 <- fread("https://data.cityofnewyork.us/resource/fhrw-4uyv.csv?agency='DSNY'&$where=created_date>='2018-01-01'&$limit=999999999999")
setDT(dsny_311)
dsny_311[, created_date := as.Date(created_date)][, yr := year(created_date)][, mo := month(created_date)]
dsny_311[, date_ym:=as.yearmon(created_date)]

dep_311 <- fread("https://data.cityofnewyork.us/resource/fhrw-4uyv.csv?agency='DEP'&$where=created_date>='2018-01-01'&$limit=999999999999")
setDT(dep_311)
dep_311[, created_date := as.Date(created_date)][, yr := year(created_date)][, mo := month(created_date)]
dep_311[, date_ym:=as.yearmon(created_date)]

# ---- street cleanliness
od_dl <- dsny_311
od_dl[complaint_type %in% c("Overflowing Litter Baskets", "Dirty Condition", "Dirty"), complaint_type := "Dirty Conditions"]
od_dl[grepl("Litter", complaint_type, ignore.case = TRUE) | grepl("litter", descriptor, ignore.case = TRUE), complaint_type := "Litter"]
od_dl_sub <- od_dl[complaint_type %in% c("Dirty Conditions", "Litter")]
# > sum((od_dl_sub[od_dl_sub$date_ym > "2022-08-01" & od_dl_sub$complaint_type == "Dirty Conditions",])$n_comp)
# [1] 47537 - from old version, littering adds ~10k
# [1] 47537 - from old version, littering adds ~3k

od_dl_sub[, n_comp := .N, by = c("complaint_type", "date_ym")] # count by complaint type, date
od_dl_sub <- od_dl_sub[, .(complaint_type, date_ym, n_comp)] # subset to complaint type, date, n
Expand Down Expand Up @@ -114,6 +128,7 @@ id_interactive <- girafe(ggobj = id_plot,
))
# htmltools::save_html(id_interactive, "../visuals/id_complaints_citywide_line.html")

dep_311_grease <- dep_311[grepl("grease", dep_311$descriptor, ignore.case = TRUE),]
# yellow/brown grease
grease_over_time_df <- dep_311_grease[dep_311_grease$date_ym >= "2022-08-01" & dep_311_grease$date_ym <= "2023-08-01",] %>%
group_by(date_ym) %>%
Expand Down

0 comments on commit 9325c2b

Please sign in to comment.