Analysis of Weather Events with Respect to Personal Harms and Financial Damages

by Andy Robaina

Synopsis: In the first part of this analysis, I found and plotted the top ten weather events in each respective category: Total Deaths, Average Death per event, Total Injuries, Average Injury per event. In the second part of the analysis, I found and plotted the top ten types of weather events that cause the most economic damage.

Data Processing

Question 1:

suppressPackageStartupMessages({
  library(dplyr)
  library(ggplot2)
  library(tidyr)
  library(patchwork)
})
## Warning: package 'ggplot2' was built under R version 4.3.3
## Warning: package 'patchwork' was built under R version 4.3.3
library(dplyr)
library(tidyr)
library(ggplot2)

#Read CSV file
data <- read.csv("/Users/andyrobaina/desktop/repdata_data_StormData.csv")

#Filter for relevant data, group by event type, sum total and avg fatalities, sum total and avg injuries. 
y <- data %>%
  select(EVTYPE, FATALITIES, INJURIES) %>%
  group_by(EVTYPE) %>%
  summarize(
    total_deaths   = sum(FATALITIES, na.rm = TRUE),
    total_injuries = sum(INJURIES,   na.rm = TRUE),
    avg_deaths     = mean(FATALITIES, na.rm = TRUE),
    avg_injuries   = mean(INJURIES,   na.rm = TRUE),
    .groups = "drop")

#Filter rows of dataframe that have related injuries or fatalities. 
z <- y %>% filter(total_deaths != 0 | total_injuries != 0)

# Make plotting function
plot_top10 <- function(df, metric, title, ylab) {
  df %>%
    arrange(desc({{ metric }})) %>%
    slice(1:10) %>%
    ggplot(aes(x = reorder(EVTYPE, {{ metric }}), y = {{ metric }})) +
    geom_col() +
    coord_flip() +
    labs(x = "Event type", y = ylab, title = title) +
    theme_minimal()
}

# Make plots
p_total_deaths   <- plot_top10(z, total_deaths,   
          "Top 10 Event Types by Total Fatalities",   "Total fatalities")
p_avg_deaths     <- plot_top10(z, avg_deaths,     
          "Top 10 Event Types by Average Fatalities", "Average fatalities per record")
p_total_injuries <- plot_top10(z, total_injuries, 
          "Top 10 Event Types by Total Injuries",     "Total injuries")
p_avg_injuries   <- plot_top10(z, avg_injuries,   
          "Top 10 Event Types by Average Injuries",   "Average injuries per record")

# Print plots
(p_total_deaths | p_avg_deaths) /
(p_total_injuries | p_avg_injuries)

Question 2:

suppressPackageStartupMessages({
  library(dplyr)
  library(ggplot2)
  library(tidyr)
})
library(dplyr)
library(tidyr)
library(ggplot2)

#Read csv file
data <- read.csv("/Users/andyrobaina/desktop/data.csv")

#Filter for relevant variables
x <- select(data, EVTYPE, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)

#Convert damage amount symbols to numbers
exp_map <- c("H" = 1e2, "h" = 1e2,
             "K" = 1e3, "k" = 1e3,
             "M" = 1e6, "m" = 1e6,
             "B" = 1e9, "b" = 1e9)

#Add column of total economic damage
x <- x %>%
  mutate(
    prop_mult = ifelse(PROPDMGEXP %in% names(exp_map), exp_map[PROPDMGEXP], 1),
    crop_mult = ifelse(CROPDMGEXP %in% names(exp_map), exp_map[CROPDMGEXP], 1),
    total_damage = (PROPDMG * prop_mult) + (CROPDMG * crop_mult)
  )

#Sum total economic damage for each event type
x_summed <- x %>%
  group_by(EVTYPE) %>%
  summarize(total_damage = sum(total_damage, na.rm = TRUE), .groups = "drop") %>%
  arrange(desc(total_damage)) %>%
  slice(1:20)

#Plot top 10 event types with respect to ecoomic damage
ggplot(x_summed, aes(x = reorder(EVTYPE, total_damage), y = total_damage)) +
  geom_col() +
  coord_flip() +
  labs(x = "Event type", y = "Total cost ($)", title = "Top 20 Event Types by Total Economic Damage") +
  theme_minimal()

Results

As we can see from the graphs, the results are as follows:

  1. Top 10 events by total fatalities were, from greatest to least: tornadoes, excessive heat, flash floods, heat, lightning, TSTM wind, floods, rip currents, high winds, avalanches.

  2. Top 10 events by average fatalities were, from greatest to least: tornadoes/TSTM wind/hail, cold/snow, tropical storm gordon, record/excessive heat, extreme heat, high wind/seas, heat wave drought, marine mishap, winter storms, high wind and seas.

  3. Top 10 events by total injuries were, from greatest to least: tornadoes, TSTM wind, floods, excessive heat, lightning, heat, ice storms, flash floods, thunderstorm/wind, hail.

  4. Top 10 events by average injuries were, from greatest to least: heat waves, tropical storm gordons, wildfires, thunderstorms, high wind/seas, snow/high winds, winter storm high winds, heat wave droughts, glaze/ice storm, hurricane/typhoon.

  5. In addition, the top 20 types of events by total economic damage were, from greatest to least: floods, hurricane/typhoons, tornadoes, storm surges, hail, flash floods, droughts, hurricanes, river floods, ice storms, tropical storms, winter storms, high winds, wildfires, TSTM winds, storm surges/tides, thunderstorms/winds, hurricane opals, wild/forest fires, heavy rainy/severe weather.