This analysis explores severe weather events and identifies which are most harmful to population health and economy.
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.5.3
##
## Attaching package: 'dplyr'
## 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 <- read.csv("repdata_data_StormData.csv.bz2")
data$FATALITIES <- as.numeric(data$FATALITIES)
data$INJURIES <- as.numeric(data$INJURIES)
health <- data %>%
group_by(EVTYPE) %>%
summarise(total = sum(FATALITIES + INJURIES)) %>%
arrange(desc(total))
data$PROPDMGEXP[data$PROPDMGEXP == "K"] <- 1e3
data$PROPDMGEXP[data$PROPDMGEXP == "M"] <- 1e6
data$PROPDMGEXP[data$PROPDMGEXP == "B"] <- 1e9
data$PROPDMGEXP <- as.numeric(data$PROPDMGEXP)
## Warning: NAs introduced by coercion
data$economic <- data$PROPDMG * data$PROPDMGEXP
economic <- data %>%
group_by(EVTYPE) %>%
summarise(total = sum(economic, na.rm = TRUE)) %>%
arrange(desc(total))
top_health <- head(health, 10)
ggplot(top_health, aes(x = reorder(EVTYPE, total), y = total)) +
geom_bar(stat = "identity") +
coord_flip() +
ggtitle("Top Events Harmful to Population Health")
top_economic <- head(economic, 10)
ggplot(top_economic, aes(x = reorder(EVTYPE, total), y = total)) +
geom_bar(stat = "identity") +
coord_flip() +
ggtitle("Top Events Causing Economic Damage")