Load packages

library(readr)
library(dplyr)
library(stringr)
library(ggplot2)

Synopsis

This analysis uses the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database to present the types of severe weather events that cause the most significant health (injuries/fatalites) and economic (property damage) effects. A key finding is that tornados cause the most significant effects to all three indicators.

Data Processing

# Read in the data 
storms <- read_csv(paste0("repdata_data_StormData.csv.bz2"))
## Rows: 902297 Columns: 37
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): BGN_DATE, BGN_TIME, TIME_ZONE, COUNTYNAME, STATE, EVTYPE, BGN_AZI,...
## dbl (18): STATE__, COUNTY, BGN_RANGE, COUNTY_END, END_RANGE, LENGTH, WIDTH, ...
## lgl  (1): COUNTYENDN
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#Get rid of summary observations
storms <- storms[grepl("Summary", storms$EVTYPE)=="FALSE",]

#drop if EVTYPE is "?" 
storms <- storms[!storms$EVTYPE=="?",]

#Ensure EVTYPE is all uppercase
storms$EVTYPE <- toupper(storms$EVTYPE)

#Correct some typos in EVTYPE
storms$EVTYPE[storms$EVTYPE=="AVALANCE"] <- "AVALANCHE"
storms$EVTYPE[storms$EVTYPE=="BEACH EROSIN"] <- "BEACH EROSION"

Results

#Q1: Across the United States, which types of events (as indicated in the # EVTYPE variable) are most harmful with respect to population health?

Tornadoes are by far the most harmful with respect to population health as estimated using both fatalities and injuries (figures below).

#1. Fatalities
fatalities <- storms %>% 
    select(EVTYPE, FATALITIES) %>%
    group_by(EVTYPE) %>%
    summarize(FATALITIES = sum(FATALITIES))

top10_f<- fatalities %>% 
    arrange(desc(FATALITIES))%>%
    slice(1:10) %>%
    as.data.frame()

#Make EV type an ordered factor so it plots in order (descending)
top10_f$EVTYPE <- factor(top10_f$EVTYPE, levels = top10_f$EVTYPE)
 
ggplot (top10_f, aes(EVTYPE, FATALITIES)) + geom_col(fill="darkblue") +
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
    labs(title="Total Number of Fatalities") + xlab("Event Type") + ylab("Number of Fatalities")
Fatalities

Fatalities

#2. Injuries 
injuries <- storms %>% 
    select(EVTYPE, INJURIES) %>%
    group_by(EVTYPE) %>%
    summarize(INJURIES = sum(INJURIES))


top10_i<- injuries %>% 
    arrange(desc(INJURIES))%>%
    slice(1:10) %>%
    as.data.frame()

#Make EV type an ordered factor so it plots in order (descending)
top10_i$EVTYPE <- factor(top10_i$EVTYPE, levels = top10_i$EVTYPE)
 
ggplot (top10_i, aes(EVTYPE, INJURIES)) + geom_col(fill="darkgreen") +
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
    labs(title="Total Number of Injuries") + xlab("Event Type") + ylab("Number of Injuries")

Q2: Across the United States, which types of events have the greatest economic consequences?

Tornadoes have the most significant economic consequences as estimated through property damage (below).

#3. Economic Consequences  
propdmg <- storms %>% 
    select(EVTYPE, PROPDMG) %>%
    group_by(EVTYPE) %>%
    summarize(PROPDMG = sum(PROPDMG))


top10_p <- propdmg %>% 
    arrange(desc(PROPDMG))%>%
    slice(1:10) %>%
    as.data.frame()

#Make EV type an ordered factor so it plots in order (descending)
top10_p$EVTYPE <- factor(top10_p$EVTYPE, levels = top10_p$EVTYPE)
 
ggplot (top10_p, aes(EVTYPE, PROPDMG)) + geom_col(fill="purple") +
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
    labs(title="Total Amount of Property Damage") + xlab("Event Type") + ylab("Number of Injuries")