Synopsis

This analysis explores the NOAA Storm Database to determine which types of weather events are most harmful to population health and which have the greatest economic consequences.

Data Processing

library(data.table)
## Warning: package 'data.table' was built under R version 4.5.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.5.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:data.table':
## 
##     between, first, last
## 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.5.3
data <- fread("repdata_data_StormData.csv.bz2")
data <- data %>%
  select(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)
convert_exp <- function(exp) {
  if (exp == "K") return(1000)
  if (exp == "M") return(1e6)
  if (exp == "B") return(1e9)
  return(1)
}

data$PROP_MULT <- sapply(data$PROPDMGEXP, convert_exp)
data$CROP_MULT <- sapply(data$CROPDMGEXP, convert_exp)

data$PROP_TOTAL <- data$PROPDMG * data$PROP_MULT
data$CROP_TOTAL <- data$CROPDMG * data$CROP_MULT

data$TOTAL_DAMAGE <- data$PROP_TOTAL + data$CROP_TOTAL
health <- data %>%
  group_by(EVTYPE) %>%
  summarise(TOTAL_HEALTH = sum(FATALITIES + INJURIES)) %>%
  arrange(desc(TOTAL_HEALTH)) %>%
  head(10)
economic <- data %>%
  group_by(EVTYPE) %>%
  summarise(TOTAL_DAMAGE = sum(TOTAL_DAMAGE)) %>%
  arrange(desc(TOTAL_DAMAGE)) %>%
  head(10)
ggplot(health, aes(x = reorder(EVTYPE, TOTAL_HEALTH), y = TOTAL_HEALTH)) +
  geom_bar(stat = "identity") +
  coord_flip()

ggplot(economic, aes(x = reorder(EVTYPE, TOTAL_DAMAGE), y = TOTAL_DAMAGE)) +
  geom_bar(stat = "identity") +
  coord_flip()