This report analyzes storm event data from the U.S. National Oceanic and Atmospheric Administration (NOAA) to identify which types of events are most harmful to population health (fatalities and injuries) and which cause the greatest economic damage (property and crop damage). The analysis shows that tornadoes are the most dangerous to human life, while floods result in the highest economic losses.
library(tidyverse)
library(ggplot2)
library(dplyr)
library(tidyr)
First we will read in the data from our csv and take a look at the first five rows.
data <- read.csv("repdata_data_StormData.csv.bz2")
head(data)
## STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE EVTYPE
## 1 1 4/18/1950 0:00:00 0130 CST 97 MOBILE AL TORNADO
## 2 1 4/18/1950 0:00:00 0145 CST 3 BALDWIN AL TORNADO
## 3 1 2/20/1951 0:00:00 1600 CST 57 FAYETTE AL TORNADO
## 4 1 6/8/1951 0:00:00 0900 CST 89 MADISON AL TORNADO
## 5 1 11/15/1951 0:00:00 1500 CST 43 CULLMAN AL TORNADO
## 6 1 11/15/1951 0:00:00 2000 CST 77 LAUDERDALE AL TORNADO
## BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END COUNTYENDN
## 1 0 0 NA
## 2 0 0 NA
## 3 0 0 NA
## 4 0 0 NA
## 5 0 0 NA
## 6 0 0 NA
## END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES INJURIES PROPDMG
## 1 0 14.0 100 3 0 0 15 25.0
## 2 0 2.0 150 2 0 0 0 2.5
## 3 0 0.1 123 2 0 0 2 25.0
## 4 0 0.0 100 2 0 0 2 2.5
## 5 0 0.0 150 2 0 0 2 2.5
## 6 0 1.5 177 2 0 0 6 2.5
## PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE
## 1 K 0 3040 8812
## 2 K 0 3042 8755
## 3 K 0 3340 8742
## 4 K 0 3458 8626
## 5 K 0 3412 8642
## 6 K 0 3450 8748
## LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1 3051 8806 1
## 2 0 0 2
## 3 0 0 3
## 4 0 0 4
## 5 0 0 5
## 6 0 0 6
Next we will subset the data to extract the columns we’re interested in.
event_data <- data |>
select(c("EVTYPE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")) |>
rename_all(tolower)
Now we will group the data by event type so that we can look at fatalities and injuries.
health <- event_data |>
group_by(evtype) |>
summarize(
fatalities = sum(fatalities, na.rm=TRUE),
injuries = sum(injuries, na.rm=TRUE),
.groups = 'drop'
) |>
arrange(desc(fatalities + injuries)) |>
slice(1:10) |>
pivot_longer(cols=c(fatalities, injuries), names_to="type", values_to="count")
First, inspect the exponent columns:
unique(event_data$propdmgexp)
## [1] "K" "M" "" "B" "m" "+" "0" "5" "6" "?" "4" "2" "3" "h" "7" "H" "-" "1" "8"
unique(event_data$cropdmgexp)
## [1] "" "M" "K" "m" "B" "?" "0" "k" "2"
Next we will write a function to deal with these exponents.
convert_exp <- function(e) {
e <- toupper(e)
dplyr::case_when(
e == "H" ~ 1e2,
e == "K" ~ 1e3,
e == "M" ~ 1e6,
e == "B" ~ 1e9,
e %in% c("", "+", "-", "?") ~ 1,
grepl("^[0-8]$", e) ~ 10 ^ as.numeric(e),
TRUE ~ 1
)
}
Next we will use this function to calculate economic damage by event type.
economic <- event_data |>
mutate(
prop_exp = convert_exp(propdmgexp),
crop_exp = convert_exp(cropdmgexp),
prop_dmg_total = propdmg * prop_exp,
crop_dmg_total = cropdmg * crop_exp
) |>
group_by(evtype) |>
summarize(
property = sum(prop_dmg_total, na.rm=TRUE),
crop=sum(crop_dmg_total, na.rm=TRUE),
.groups='drop'
) |>
arrange(desc(property + crop)) |>
slice(1:10) |>
pivot_longer(cols=c(property, crop), names_to="type", values_to="damage")
Tornadoes are by far the leading cause of fatalities and injuries, suggesting a need for improved forecasting, infrastructure, and public education in tornado-prone areas.
ggplot(data=health, aes(x=reorder(evtype, -count), y=count, fill=type)) +
geom_bar(position="dodge", stat="identity") +
labs(title="Tope 10 Weather Events Causing Injuries and Fatalities", x="event Type", y="Number of People Affected") +
scale_fill_manual(values=c("purple4", "mediumpurple1")) +
theme_minimal() +
theme(axis.text.x=element_text(angle=45, hjust=1))
Floods account for the greatest overall economic losses in the U.S., particularly through extensive property damage, although droughts account for the greatest amount of crop damage.
ggplot(data=economic, aes(x=reorder(evtype, -damage), y=damage / 1e9, fill=type)) +
geom_bar(position="dodge", stat="identity") +
labs(title="Top 10 Weather Events by Economic Damage", x="Event Type", y="Damage (Billion USD)") +
scale_fill_manual(values=c("navy", "steelblue1")) +
theme_minimal() +
theme(axis.text.x=element_text(angle=45, hjust=1))