Exploring weather event data through R shows the destructive power of extreme events such as floods and tornados. The impact is measured through property damage, injuries and deaths.
Processing begins with installing needed libraries then moves to downloading and cleaning data
suppressMessages(library(ggplot2))
suppressMessages(library(tidyverse))
suppressMessages(library(dplyr))
suppressMessages(library(rmarkdown))
suppressMessages(library(knitr))
suppressMessages(library(lubridate))
if(!file.exists('repdata-data-StormData.csv.bz2')){
unzip('StormData.zip')
}
activityData <- read.csv('StormData.csv')
Next we limit the fields to those necessary for the subsequent analysis Then narrow the range of the data to the years from 2000 until 2012
df1 <- select(activityData,
EVTYPE,
BGN_DATE,
FATALITIES,
INJURIES,
PROPDMG,
PROPDMGEXP,
CROPDMG,
CROPDMGEXP) %>%
# Filter weather events from 1996 onwards
mutate(BGN_DATE = mdy_hm(BGN_DATE)) %>%
filter(year(BGN_DATE) >= 2000 & year(BGN_DATE)<= 2012)
a <- length(unique(activityData$EVTYPE))
b <- length(unique(df1$EVTYPE))
The raw data has a large range of event types. In a more thorough analysis this data could be narrowed by combining incidents. However by restricting the range of years we see a reduction from 1013 to 196.
The next processing further combines and narrows data for to calculate the most harmful types of events for population health
df2 <- group_by(df1, EVTYPE)
eventdata <- data.frame(summarise(df1,
totalfatal = sum(as.double(FATALITIES)),
totalinjuries = sum(as.double(INJURIES))))
results.injuries <- group_by(df2, EVTYPE) %>%
summarise(INJURIES = sum(as.double(INJURIES))) %>%
top_n(20, INJURIES)
results.fatalities <- group_by(df2, EVTYPE) %>%
summarise(FATALITIES = sum(as.double(FATALITIES))) %>%
top_n(20, FATALITIES)
top20fatalities <- head(arrange(results.fatalities, desc(FATALITIES)), 20)
top20injuries <- head(arrange(results.injuries, desc(INJURIES)), 20)
Next we process the data for the types of economic consequences by combining property and crop damage
df1$PROPDMG <- as.numeric(df1$PROPDMG)
df1$CROPDMG <- as.numeric(df1$CROPDMG)
noaa.subset <- mutate(df1,
# Capitalize multiplier codes
PROPDMGEXP = toupper(PROPDMGEXP),
CROPDMGEXP = toupper(CROPDMGEXP),
# Multiply base damage with appropriate multiplier
PROPDMG.TOTAL = case_when(
PROPDMGEXP == "H" ~ PROPDMG * 1e+02, # Hundreds
PROPDMGEXP == "K" ~ PROPDMG * 1e+03, # Thousands
PROPDMGEXP == "M" ~ PROPDMG * 1e+06, # Millions
PROPDMGEXP == "B" ~ PROPDMG * 1e+09, # Billions
grepl("[0-9]", PROPDMGEXP) ~ PROPDMG * 10^as.numeric(PROPDMGEXP),
TRUE ~ PROPDMG),
CROPDMG.TOTAL = case_when(
CROPDMGEXP == "H" ~ CROPDMG * 1e+02, # Hundreds
CROPDMGEXP == "K" ~ CROPDMG * 1e+03, # Thousand
CROPDMGEXP == "M" ~ CROPDMG * 1e+06, # Millions
CROPDMGEXP == "B" ~ CROPDMG * 1e+09, # Billions
grepl("[0-9]", CROPDMGEXP) ~ PROPDMG * 10^as.numeric(CROPDMGEXP),
TRUE ~ CROPDMG))
What follows is the data based on the analysis …
ggplot(results.fatalities, aes(reorder(EVTYPE, FATALITIES), FATALITIES)) +
geom_col() +
coord_flip() +
labs(y = "Fatalities",
x = "Severe Weather",
title = "Figure 1. Fatalities in the US from weather events from 2000-2011") +
scale_y_continuous() +
theme_light() +
theme(axis.title.y = element_blank(),
plot.title = element_text(size = 12,
face = "bold"))
ggplot(results.injuries, aes(reorder(EVTYPE, INJURIES), INJURIES)) +
geom_col() +
coord_flip() +
labs(y = "Injuries",
x = "Severe Weather",
title = "Figure 2. Injuries in the US from weather events from 2000-2011") +
scale_y_continuous() +
theme_light() +
theme(axis.title.y = element_blank(),
plot.title = element_text(size = 12,
face = "bold"))
results.economic <- group_by(noaa.subset, EVTYPE) %>%
summarise(TOTAL.PROP.DMG = sum(PROPDMG.TOTAL),
TOTAL.CROP.DMG = sum(CROPDMG.TOTAL)) %>%
mutate(TOTAL.DMG = TOTAL.PROP.DMG + TOTAL.CROP.DMG) %>%
top_n(10, TOTAL.DMG)
results.economic <- select(results.economic, -TOTAL.DMG) %>%
gather("DMG.TYPE", "DMG.DOLLARS.BILLION", -EVTYPE) %>%
mutate(DMG.DOLLARS.BILLION = round(DMG.DOLLARS.BILLION / 1e+09, 2),
DMG.TYPE = recode_factor(DMG.TYPE,
TOTAL.CROP.DMG = "Crop",
TOTAL.PROP.DMG = "Property"))
ggplot(results.economic, aes(reorder(EVTYPE, DMG.DOLLARS.BILLION),
DMG.DOLLARS.BILLION, fill = DMG.TYPE)) +
geom_col() +
coord_flip() +
labs(y = "Billions of Dollars",
x = "Severe Weather",
fill = "Damage",
title = "Figure 3. Damage in the US from severe weather events from 2000") +
guides(fill = guide_legend(reverse=T)) +
scale_y_continuous() +
theme_light() +
theme(legend.position = "bottom",
axis.title.y = element_blank(),
plot.title = element_text(size = 12,
face = "bold"))
The human cost from weather events is concentrated in Tornados and Excessive Heat. While the economic cost is concentrated in floods and hurricanes.