library(tidyverse)
library(tidymodels)TRASH_DataVisualization 110
Introduction
This project analyzes the Baltimore Trash Collection dataset from 2014 to 2023. The dataset contains information about dumpster waste collection, including collection dates, dumpster identification numbers, trash weight, trash volume, and different categories of waste such as plastic bottles, plastic bags, wrappers, cigarette butts, and glass bottles.
The goal of this analysis is to explore patterns in Baltimore’s trash collection and investigate how waste amounts changed over time. In addition, this project examines the composition of collected waste to identify which types of trash contributed the most to overall waste.
The original dataset was obtained from the Baltimore City Open Data Portal(https://www.baltimorecountymd.gov/open-data). The data were collected as part of Baltimore’s municipal waste management activities.
Loading The Data
setwd("~/Documents/DATA SCIENCE/DATA 110/Project 1")
read_csv("trash_collection_Baltimore_2014-23.csv")# A tibble: 630 × 16
Dumpster Month Year Date `Weight (tons)` `Volume (cubic yards)`
<dbl> <chr> <dbl> <chr> <dbl> <dbl>
1 1 May 2014 5/16/2014 4.31 18
2 2 May 2014 5/16/2014 2.74 13
3 3 May 2014 5/16/2014 3.45 15
4 4 May 2014 5/17/2014 3.1 15
5 5 May 2014 5/17/2014 4.06 18
6 6 May 2014 5/20/2014 2.71 13
7 7 May 2014 5/21/2014 1.91 8
8 8 May 2014 5/28/2014 3.7 16
9 9 June 2014 6/5/2014 2.52 14
10 10 June 2014 6/11/2014 3.76 18
# ℹ 620 more rows
# ℹ 10 more variables: `Plastic Bottles` <dbl>, Polystyrene <dbl>,
# `Cigarette Butts` <dbl>, `Glass Bottles` <dbl>, `Plastic Bags` <dbl>,
# Wrappers <dbl>, `Sports Balls` <dbl>, `Homes Powered*` <dbl>, ...15 <lgl>,
# ...16 <lgl>
trash <- read_csv("trash_collection_Baltimore_2014-23.csv")
head(trash)# A tibble: 6 × 16
Dumpster Month Year Date `Weight (tons)` `Volume (cubic yards)`
<dbl> <chr> <dbl> <chr> <dbl> <dbl>
1 1 May 2014 5/16/2014 4.31 18
2 2 May 2014 5/16/2014 2.74 13
3 3 May 2014 5/16/2014 3.45 15
4 4 May 2014 5/17/2014 3.1 15
5 5 May 2014 5/17/2014 4.06 18
6 6 May 2014 5/20/2014 2.71 13
# ℹ 10 more variables: `Plastic Bottles` <dbl>, Polystyrene <dbl>,
# `Cigarette Butts` <dbl>, `Glass Bottles` <dbl>, `Plastic Bags` <dbl>,
# Wrappers <dbl>, `Sports Balls` <dbl>, `Homes Powered*` <dbl>, ...15 <lgl>,
# ...16 <lgl>
Data Cleaning
glimpse(trash)Rows: 630
Columns: 16
$ Dumpster <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …
$ Month <chr> "May", "May", "May", "May", "May", "May", "May"…
$ Year <dbl> 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014,…
$ Date <chr> "5/16/2014", "5/16/2014", "5/16/2014", "5/17/20…
$ `Weight (tons)` <dbl> 4.31, 2.74, 3.45, 3.10, 4.06, 2.71, 1.91, 3.70,…
$ `Volume (cubic yards)` <dbl> 18, 13, 15, 15, 18, 13, 8, 16, 14, 18, 15, 19, …
$ `Plastic Bottles` <dbl> 1450, 1120, 2450, 2380, 980, 1430, 910, 3580, 2…
$ Polystyrene <dbl> 1820, 1030, 3100, 2730, 870, 2140, 1090, 4310, …
$ `Cigarette Butts` <dbl> 126000, 91000, 105000, 100000, 120000, 90000, 5…
$ `Glass Bottles` <dbl> 72, 42, 50, 52, 72, 46, 32, 58, 49, 75, 38, 45,…
$ `Plastic Bags` <dbl> 584, 496, 1080, 896, 368, 672, 416, 1552, 984, …
$ Wrappers <dbl> 1162, 874, 2032, 1971, 753, 1144, 692, 3015, 19…
$ `Sports Balls` <dbl> 7, 5, 6, 6, 7, 5, 3, 6, 6, 7, 6, 8, 6, 6, 6, 6,…
$ `Homes Powered*` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ ...15 <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ ...16 <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
colnames(trash) [1] "Dumpster" "Month" "Year"
[4] "Date" "Weight (tons)" "Volume (cubic yards)"
[7] "Plastic Bottles" "Polystyrene" "Cigarette Butts"
[10] "Glass Bottles" "Plastic Bags" "Wrappers"
[13] "Sports Balls" "Homes Powered*" "...15"
[16] "...16"
summary(trash) Dumpster Month Year Date
Min. : 1 Length :630 Min. :2014 Length :630
1st Qu.:158 N.unique : 13 1st Qu.:2016 N.unique :379
Median :315 N.blank : 0 Median :2019 N.blank : 0
Mean :315 Min.nchar: 3 Mean :2019 Min.nchar: 8
3rd Qu.:472 Max.nchar: 9 3rd Qu.:2021 Max.nchar: 10
Max. :629 NAs : 1 Max. :2023 NAs : 1
NAs :1 NAs :1
Weight (tons) Volume (cubic yards) Plastic Bottles Polystyrene
Min. : 0.780 Min. : 7.00 Min. : 80 Min. : 20
1st Qu.: 2.720 1st Qu.: 15.00 1st Qu.: 1025 1st Qu.: 440
Median : 3.205 Median : 15.00 Median : 1900 Median : 1040
Mean : 6.411 Mean : 30.44 Mean : 3956 Mean : 2921
3rd Qu.: 3.730 3rd Qu.: 15.00 3rd Qu.: 2780 3rd Qu.: 2258
Max. :2019.540 Max. :9589.00 Max. :1246155 Max. :920011
Cigarette Butts Glass Bottles Plastic Bags Wrappers
Min. : 500 Min. : 0.00 Min. : 24 Min. : 180.0
1st Qu.: 3600 1st Qu.: 10.00 1st Qu.: 270 1st Qu.: 776.2
Median : 6000 Median : 18.00 Median : 551 Median : 1142.0
Mean : 37254 Mean : 42.86 Mean : 1732 Mean : 2851.2
3rd Qu.: 22000 3rd Qu.: 29.75 3rd Qu.: 1140 3rd Qu.: 1980.0
Max. :11735100 Max. :13502.00 Max. :545554 Max. :898129.0
Sports Balls Homes Powered* ...15 ...16
Min. : 0.00 Min. : 0.00 Mode:logical Mode:logical
1st Qu.: 6.00 1st Qu.: 41.00 NAs :630 NAs :630
Median : 12.00 Median : 52.00
Mean : 27.15 Mean : 95.38
3rd Qu.: 20.00 3rd Qu.: 60.75
Max. :8553.00 Max. :30020.00
colSums(is.na(trash)) Dumpster Month Year
1 1 1
Date Weight (tons) Volume (cubic yards)
1 0 0
Plastic Bottles Polystyrene Cigarette Butts
0 0 0
Glass Bottles Plastic Bags Wrappers
0 0 0
Sports Balls Homes Powered* ...15
0 0 630
...16
630
trash_clean <- trash |>
select(-...15, -...16)
head(trash_clean)# A tibble: 6 × 14
Dumpster Month Year Date `Weight (tons)` `Volume (cubic yards)`
<dbl> <chr> <dbl> <chr> <dbl> <dbl>
1 1 May 2014 5/16/2014 4.31 18
2 2 May 2014 5/16/2014 2.74 13
3 3 May 2014 5/16/2014 3.45 15
4 4 May 2014 5/17/2014 3.1 15
5 5 May 2014 5/17/2014 4.06 18
6 6 May 2014 5/20/2014 2.71 13
# ℹ 8 more variables: `Plastic Bottles` <dbl>, Polystyrene <dbl>,
# `Cigarette Butts` <dbl>, `Glass Bottles` <dbl>, `Plastic Bags` <dbl>,
# Wrappers <dbl>, `Sports Balls` <dbl>, `Homes Powered*` <dbl>
trash_clean <- trash_clean |>
drop_na(Date, Year, Month)trash_clean <- trash_clean |>
mutate(Date = as.Date(Date, format = "%m/%d/%Y"))
head(trash_clean)# A tibble: 6 × 14
Dumpster Month Year Date `Weight (tons)` `Volume (cubic yards)`
<dbl> <chr> <dbl> <date> <dbl> <dbl>
1 1 May 2014 2014-05-16 4.31 18
2 2 May 2014 2014-05-16 2.74 13
3 3 May 2014 2014-05-16 3.45 15
4 4 May 2014 2014-05-17 3.1 15
5 5 May 2014 2014-05-17 4.06 18
6 6 May 2014 2014-05-20 2.71 13
# ℹ 8 more variables: `Plastic Bottles` <dbl>, Polystyrene <dbl>,
# `Cigarette Butts` <dbl>, `Glass Bottles` <dbl>, `Plastic Bags` <dbl>,
# Wrappers <dbl>, `Sports Balls` <dbl>, `Homes Powered*` <dbl>
glimpse(trash_clean)Rows: 629
Columns: 14
$ Dumpster <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …
$ Month <chr> "May", "May", "May", "May", "May", "May", "May"…
$ Year <dbl> 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014,…
$ Date <date> 2014-05-16, 2014-05-16, 2014-05-16, 2014-05-17…
$ `Weight (tons)` <dbl> 4.31, 2.74, 3.45, 3.10, 4.06, 2.71, 1.91, 3.70,…
$ `Volume (cubic yards)` <dbl> 18, 13, 15, 15, 18, 13, 8, 16, 14, 18, 15, 19, …
$ `Plastic Bottles` <dbl> 1450, 1120, 2450, 2380, 980, 1430, 910, 3580, 2…
$ Polystyrene <dbl> 1820, 1030, 3100, 2730, 870, 2140, 1090, 4310, …
$ `Cigarette Butts` <dbl> 126000, 91000, 105000, 100000, 120000, 90000, 5…
$ `Glass Bottles` <dbl> 72, 42, 50, 52, 72, 46, 32, 58, 49, 75, 38, 45,…
$ `Plastic Bags` <dbl> 584, 496, 1080, 896, 368, 672, 416, 1552, 984, …
$ Wrappers <dbl> 1162, 874, 2032, 1971, 753, 1144, 692, 3015, 19…
$ `Sports Balls` <dbl> 7, 5, 6, 6, 7, 5, 3, 6, 6, 7, 6, 8, 6, 6, 6, 6,…
$ `Homes Powered*` <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
##Exploratory Analysis Research Question
How has the amount of trash collected in Baltimore changed from 2014 to 2023?
Response variable:
Weight (tons)
Explanatory variable:
Year
PLOT 1
ggplot(trash_clean,
aes(x = `Weight (tons)`)) +
geom_histogram(
bins = 30,
fill = "#0072B2",
color = "white"
) +
labs(
title = "Distribution of Trash Weight Collected",
x = "Weight (tons)",
y = "Number of Observations"
) +
theme_minimal()Trash weight by year
trash_year <- trash_clean |>
group_by(Year) |>
summarize(
Average_Weight = mean(`Weight (tons)`, na.rm = TRUE)
)
head(trash_year)# A tibble: 6 × 2
Year Average_Weight
<dbl> <dbl>
1 2014 3.21
2 2015 3.36
3 2016 3.23
4 2017 3.18
5 2018 3.34
6 2019 3.03
PLOT 2
ggplot(trash_year,
aes(x = Year,
y = Average_Weight)) +
geom_col(
fill = "#009E73"
) +
labs(
title = "Average Trash Weight by Year",
x = "Year",
y = "Average Weight (tons)"
) +
theme_classic()Final Visualization
Types of Trash Collected
trash_types <- trash_clean |>
summarize(
Plastic_Bottles = sum(`Plastic Bottles`),
Plastic_Bags = sum(`Plastic Bags`),
Wrappers = sum(Wrappers),
Cigarette_Butts = sum(`Cigarette Butts`),
Glass_Bottles = sum(`Glass Bottles`)
) |>
pivot_longer(
cols = everything(),
names_to = "Trash_Type",
values_to = "Total"
)
trash_types# A tibble: 5 × 2
Trash_Type Total
<chr> <dbl>
1 Plastic_Bottles 1246155
2 Plastic_Bags 545554
3 Wrappers 898129
4 Cigarette_Butts 11735100
5 Glass_Bottles 13502
PLOT 3
ggplot(trash_types,
aes(x = reorder(Trash_Type, Total),
y = Total,
fill = Trash_Type)) +
geom_col() +
coord_flip() +
scale_fill_manual(
values = c(
"#0072B2",
"#D55E00",
"#009E73",
"#CC79A7",
"#F0E442"
)
) +
labs(
title = "Composition of Waste Collected in Baltimore (2014-2023)",
x = "Trash Category",
y = "Total Items Collected",
fill = "Trash Type",
caption = "Source: Baltimore City Open Data Portal"
) +
theme_minimal()Discussion
Data Cleaning Process
During the data cleaning process, I first inspected the dataset structure and identified missing values and unnecessary variables. The dataset contained two empty columns (...15 and ...16) that did not provide any information, so these columns were removed using the select() function. I also checked for missing values and removed observations with missing information in important variables such as the date, month, and year. The Date variable was originally stored as a character variable, so it was converted into a date format using as.Date() to make it more appropriate for time-based analysis. These steps improved the quality of the dataset while preserving the majority of the original observations.
Visualization Findings
The final visualization represents the amount and composition of waste collected in Baltimore from 2014 to 2023. The graph compares different categories of waste, including plastic bottles, plastic bags, wrappers, cigarette butts, and glass bottles. One interesting pattern observed in the visualization is that some types of waste occur at much higher levels than others. In particular, cigarette butts and plastic-related materials represent a much larger portion of the collected waste compared with categories such as glass bottles or sports balls. This suggests that single-use consumer products contribute significantly to the waste collected in the city.
Limitations and Additional Analysis
During this project, I wanted to explore additional factors that could influence trash collection, such as differences between neighborhoods, population density, or seasonal changes. However, the dataset did not include location information or enough demographic data to perform those analyses. Another possible improvement would be comparing waste categories over time to determine whether certain types of trash increased or decreased between 2014 and 2023. Including additional environmental or demographic datasets could provide more context for future analysis.