The basic goal of this assignment is to explore the U.S. NOAA Storm Database to address two key questions:
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.3
##
## 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)
# Load dataset (file should be in same folder as .Rmd)
storm_data <- read.csv("C:/Users/jmorris/Documents/RR project2/repdata_data_StormData (1).csv/repdata_data_StormData (1).csv", stringsAsFactors = FALSE)
# Select relevant variables
data <- storm_data %>%
select(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP,
CROPDMG, CROPDMGEXP)
# Function to convert damage exponent values
convert_exp <- function(exp) {
ifelse(exp == "K", 1e3,
ifelse(exp == "M", 1e6,
ifelse(exp == "B", 1e9, 1)))
}
# Apply transformations
data <- data %>%
mutate(
PROP_MULT = convert_exp(PROPDMGEXP),
CROP_MULT = convert_exp(CROPDMGEXP),
PROP_DAMAGE = PROPDMG * PROP_MULT,
CROP_DAMAGE = CROPDMG * CROP_MULT,
TOTAL_DAMAGE = PROP_DAMAGE + CROP_DAMAGE,
HEALTH_IMPACT = FATALITIES + INJURIES
)
# Health impact
health_summary <- data %>%
group_by(EVTYPE) %>%
summarise(TOTAL_HEALTH = sum(HEALTH_IMPACT, na.rm = TRUE)) %>%
arrange(desc(TOTAL_HEALTH)) %>%
slice(1:10)
# Economic impact
economic_summary <- data %>%
group_by(EVTYPE) %>%
summarise(TOTAL_DAMAGE = sum(TOTAL_DAMAGE, na.rm = TRUE)) %>%
arrange(desc(TOTAL_DAMAGE)) %>%
slice(1:10)
ggplot(health_summary, aes(x = reorder(EVTYPE, TOTAL_HEALTH), y = TOTAL_HEALTH)) +
geom_bar(stat = "identity") +
coord_flip() +
labs(
title = "Top 10 Weather Events Harmful to Population Health",
x = "Event Type",
y = "Total Fatalities and Injuries"
)
Figure 1: Tornadoes are the leading cause of harm to population health, with excessive heat and floods also contributing significantly.
ggplot(economic_summary, aes(x = reorder(EVTYPE, TOTAL_DAMAGE), y = TOTAL_DAMAGE)) +
geom_bar(stat = "identity") +
coord_flip() +
labs(
title = "Top 10 Weather Events by Economic Damage",
x = "Event Type",
y = "Total Damage (USD)"
)
Figure 2: Floods, hurricanes/typhoons, and storm surges are responsible for the highest levels of economic loss.
health_summary
## # A tibble: 10 × 2
## EVTYPE TOTAL_HEALTH
## <chr> <dbl>
## 1 TORNADO 96979
## 2 EXCESSIVE HEAT 8428
## 3 TSTM WIND 7461
## 4 FLOOD 7259
## 5 LIGHTNING 6046
## 6 HEAT 3037
## 7 FLASH FLOOD 2755
## 8 ICE STORM 2064
## 9 THUNDERSTORM WIND 1621
## 10 WINTER STORM 1527
economic_summary
## # A tibble: 10 × 2
## EVTYPE TOTAL_DAMAGE
## <chr> <dbl>
## 1 FLOOD 150319678257
## 2 HURRICANE/TYPHOON 71913712800
## 3 TORNADO 57340614060.
## 4 STORM SURGE 43323541000
## 5 HAIL 18752904943.
## 6 FLASH FLOOD 17562129167.
## 7 DROUGHT 15018672000
## 8 HURRICANE 14610229010
## 9 RIVER FLOOD 10148404500
## 10 ICE STORM 8967041360
The results indicate that severe weather events pose significant risks to both human health and economic stability. Events such as tornadoes, floods, and hurricanes consistently contribute to the highest levels of injuries, fatalities, and financial losses. These findings emphasize the need for improved early warning systems and effective disaster management strategies.