This analysis delves into storm data to uncover trends in fatalities, property damage, and event occurrences. By examining and visualizing this information, the goal is to pinpoint events affecting population health and those causing significant economic impact. Through cleaning, exploration, and visualization, this report aims to reveal vital insights into impactful events and their economic consequences.
First the working environment is set and the needed libraries (dplyr and ggplot2) and data file are downloaded.
knitr::opts_chunk$set(echo = TRUE)
# Set working directory
setwd('C:/Users/User/Desktop/CourseProject2')
# Load necessary packages
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
# Load data
storm_data <- read.csv(bzfile("repdata_data_StormData.csv.bz2"))
Through meticulous data cleaning, missing values (NAs) are replaced with zeros. Additionally, property damage values are standarized by multiplying ‘PROPDMG’ by 1000. The summary ‘summary(cleaned_data)’ offer an initial glimpse into the distribution and characteristics of fatalities and property damage.
knitr::opts_chunk$set(echo = TRUE)
cleaned_data <- storm_data %>%
select(EVTYPE, FATALITIES, PROPDMG) %>%
mutate(
FATALITIES = ifelse(is.na(FATALITIES), 0, FATALITIES),
PROPDMG = ifelse(is.na(PROPDMG), 0, PROPDMG)
) %>%
mutate(PROPDMG = PROPDMG * 1000)
head(cleaned_data)
## EVTYPE FATALITIES PROPDMG
## 1 TORNADO 0 25000
## 2 TORNADO 0 2500
## 3 TORNADO 0 25000
## 4 TORNADO 0 2500
## 5 TORNADO 0 2500
## 6 TORNADO 0 2500
summary(cleaned_data)
## EVTYPE FATALITIES PROPDMG
## Length:902297 Min. : 0.0000 Min. : 0
## Class :character 1st Qu.: 0.0000 1st Qu.: 0
## Mode :character Median : 0.0000 Median : 0
## Mean : 0.0168 Mean : 12063
## 3rd Qu.: 0.0000 3rd Qu.: 500
## Max. :583.0000 Max. :5000000
The exploratory analysis aims to dissect events based on their impact on population health and economic consequences. It identifies the top 10 events with the highest fatalities, shedding light on those that pose the most significant threat to human life. At the same time, it discerns events causing substantial property damage, presenting the top 10 events with the most severe economic implications,
knitr::opts_chunk$set(echo = TRUE)
# Identify events impacting population health
events_health <- cleaned_data %>%
group_by(EVTYPE) %>%
summarise(total_fatalities = sum(FATALITIES)) %>%
top_n(10, total_fatalities)
# Identify events with economic consequences
events_economic <- cleaned_data %>%
group_by(EVTYPE) %>%
summarise(total_property_damage = sum(PROPDMG)) %>%
top_n(10, total_property_damage)
# Present findings regarding events impacting population health
print(events_health)
## # A tibble: 10 × 2
## EVTYPE total_fatalities
## <chr> <dbl>
## 1 AVALANCHE 224
## 2 EXCESSIVE HEAT 1903
## 3 FLASH FLOOD 978
## 4 FLOOD 470
## 5 HEAT 937
## 6 HIGH WIND 248
## 7 LIGHTNING 816
## 8 RIP CURRENT 368
## 9 TORNADO 5633
## 10 TSTM WIND 504
# Present findings regarding events with economic consequences
print(events_economic)
## # A tibble: 10 × 2
## EVTYPE total_property_damage
## <chr> <dbl>
## 1 FLASH FLOOD 1420124590
## 2 FLOOD 899938480
## 3 HAIL 688693380
## 4 HIGH WIND 324731560
## 5 LIGHTNING 603351780
## 6 THUNDERSTORM WIND 876844170
## 7 THUNDERSTORM WINDS 446293180
## 8 TORNADO 3212258160
## 9 TSTM WIND 1335965610
## 10 WINTER STORM 132720590
Once all the data is cleaned and explore, it is important to show it in a clear manner. This is done through different plots in order to see the results and the data is implemented.
knitr::opts_chunk$set(echo = TRUE)
event_counts <- cleaned_data %>%
group_by(EVTYPE) %>%
summarise(count = n()) %>%
top_n(10, count)
ggplot(event_counts, aes(x = reorder(EVTYPE, -count), y = count)) +
geom_bar(stat = "identity", fill = "lightgreen") +
labs(title = "Top Event Types by Occurrence",
x = "Event Types",
y = "Count of Occurrences") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
knitr::opts_chunk$set(echo = TRUE)
# Bar plot
ggplot(events_health, aes(x = reorder(EVTYPE, -total_fatalities), y = total_fatalities)) +
geom_bar(stat = "identity", fill = "skyblue") +
labs(title = "Top Event Types by Fatalities",
x = "Event Types",
y = "Total Fatalities") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# Pie chart
ggplot(events_health, aes(x = "", y = total_fatalities, fill = EVTYPE)) +
geom_bar(stat = "identity", width = 1, color = "white") +
coord_polar("y", start = 0) +
labs(title = "Proportion of Fatalities by Event Type",
fill = "Event Type",
x = NULL,
y = NULL) +
theme_void() +
theme(legend.position = "bottom")
knitr::opts_chunk$set(echo = TRUE)
# Bar plot
ggplot(events_economic, aes(x = reorder(EVTYPE, -total_property_damage), y = total_property_damage)) +
geom_bar(stat = "identity", fill = "salmon") +
labs(title = "Top Event Types by Property Damage",
x = "Event Types",
y = "Total Property Damage") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# Pie chart
ggplot(events_economic, aes(x = "", y = total_property_damage, fill = EVTYPE)) +
geom_bar(stat = "identity", width = 1, color = "white") +
coord_polar("y", start = 0) +
labs(title = "Proportion of Property Damage by Event Type",
fill = "Event Type",
x = NULL,
y = NULL) +
theme_void() +
theme(legend.position = "bottom")