Synopsis

This analysis explores the NOAA Storm Database to identify the most harmful weather events in the United States. It focuses on the impact of these events on both population health (fatalities and injuries) and economic consequences (property and crop damage). The analysis uses the dplyr and ggplot2 packages in R to process and visualize the data. The results highlight the most significant event types in terms of both health and economic impacts, providing valuable insights for government and municipal managers responsible for disaster preparedness and resource allocation.

knitr::opts_chunk$set(echo = TRUE)





## Data Processing

# Load necessary libraries
library(dplyr)
## 
## 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)

# Download and read the data 
# Source: NOAA Storm Database ([https://www.ncdc.noaa.gov/stormevents/](https://www.ncdc.noaa.gov/stormevents/))
storm_data <- read.csv(file.choose(), header = TRUE, stringsAsFactors = FALSE) 


# Select relevant columns for analysis
storm_data <- storm_data %>% 
  select(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)

# Clean event types (EVTYPE)
# Standardize event types for accurate analysis by removing punctuation, 
# converting to lowercase, and removing leading/trailing whitespace
storm_data$EVTYPE <- tolower(storm_data$EVTYPE)  # Convert to lowercase
storm_data$EVTYPE <- gsub("[[:punct:]]", "", storm_data$EVTYPE)  # Remove punctuation
storm_data$EVTYPE <- trimws(storm_data$EVTYPE)  # Remove leading/trailing whitespace

# Convert property and crop damage exponents to multipliers
# This step converts the letter exponents (K, M, B) to their numeric equivalents
storm_data <- storm_data %>% mutate(
  PROPDMGEXP = case_when(
    PROPDMGEXP == "K" ~ 1e3,
    PROPDMGEXP == "M" ~ 1e6,
    PROPDMGEXP == "B" ~ 1e9,
    TRUE ~ 1  # If no exponent, assume a multiplier of 1
  ),
  CROPDMGEXP = case_when(
    CROPDMGEXP == "K" ~ 1e3,
    CROPDMGEXP == "M" ~ 1e6,
    CROPDMGEXP == "B" ~ 1e9,
    TRUE ~ 1  # If no exponent, assume a multiplier of 1
  )
)

# Calculate total property and crop damage
storm_data <- storm_data %>% mutate(
  TOTAL_PROPDMG = PROPDMG * PROPDMGEXP,
  TOTAL_CROPDMG = CROPDMG * CROPDMGEXP
)


# --- Analysis and Results ---

# --- 1. Most harmful events with respect to population health ---

# Calculate total fatalities and injuries by event type
health_impact <- storm_data %>% 
  group_by(EVTYPE) %>% 
  summarize(
    TOTAL_FATALITIES = sum(FATALITIES),
    TOTAL_INJURIES = sum(INJURIES)
  ) %>% 
  arrange(desc(TOTAL_FATALITIES), desc(TOTAL_INJURIES))

# Top 10 events causing fatalities
top_10_fatalities <- head(health_impact, 10)

# Top 10 events causing injuries
top_10_injuries <- health_impact %>% arrange(desc(TOTAL_INJURIES)) %>% head(10)

# Plot top 10 events causing fatalities
ggplot(top_10_fatalities, aes(x = reorder(EVTYPE, -TOTAL_FATALITIES), y = TOTAL_FATALITIES)) +
  geom_bar(stat = "identity", fill = "red") +
  labs(title = "Top 10 Events Causing Fatalities", x = "Event Type", y = "Total Fatalities") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Plot top 10 events causing injuries
ggplot(top_10_injuries, aes(x = reorder(EVTYPE, -TOTAL_INJURIES), y = TOTAL_INJURIES)) +
  geom_bar(stat = "identity", fill = "blue") +
  labs(title = "Top 10 Events Causing Injuries", x = "Event Type", y = "Total Injuries") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# --- 2. Events with greatest economic consequences ---

# Calculate total property and crop damage by event type
economic_impact <- storm_data %>% 
  group_by(EVTYPE) %>% 
  summarize(
    TOTAL_PROPDMG = sum(TOTAL_PROPDMG),
    TOTAL_CROPDMG = sum(TOTAL_CROPDMG)
  ) %>% 
  arrange(desc(TOTAL_PROPDMG), desc(TOTAL_CROPDMG))

# Top 10 events causing property damage
top_10_propdmg <- head(economic_impact, 10)

# Top 10 events causing crop damage
top_10_cropdmg <- economic_impact %>% arrange(desc(TOTAL_CROPDMG)) %>% head(10)

# Plot top 10 events causing property damage
ggplot(top_10_propdmg, aes(x = reorder(EVTYPE, -TOTAL_PROPDMG), y = TOTAL_PROPDMG)) +
  geom_bar(stat = "identity", fill = "green") +
  labs(title = "Top 10 Events Causing Property Damage", 
       x = "Event Type", 
       y = "Total Property Damage (<span class='math'></span>)") + # Use single quotes within the HTML tag
  theme(axis.text.x = element_text(angle = 45, hjust = 1))