Data Procesing
# For the following variables, calculate the total number per event type followed
# by ordering and extracting the top 10 rows: FATALITIES & INJURIES.
total_fatalities <- ddply(storm, c("EVTYPE"), summarise, sum = sum(FATALITIES))
total_fatalities <- total_fatalities[order(total_fatalities$sum, decreasing = T),
][1:10, ]
total_injuries <- ddply(storm, c("EVTYPE"), summarise, sum = sum(INJURIES))
total_injuries <- total_injuries[order(total_injuries$sum, decreasing = T), ][1:10,
]
# Correct the values for PROPDMGEXP of 'H', 'K', and 'M' to multiply the PROPDMG
# by 100, 1000, and 100000, respectively
storm$CorrectedValue <- ifelse(storm$PROPDMGEXP == "H", storm$PROPDMG * 100, ifelse(storm$PROPDMGEXP ==
"K", storm$PROPDMG * 1000, ifelse(storm$PROPDMGEXP == "M", storm$PROPDMG * 1e+06,
"NA")))
# Coerce the values generated from the previous line of code into the numeric
# class
storm$CorrectedValue <- as.numeric(storm$CorrectedValue)
## Warning: NAs introduced by coercion
# For the following variables, calculate the total number per event type followed
# by ordering and extracting the top 10 rows: PROPDMG & CROPDMG
total_prop_damage <- ddply(storm, c("EVTYPE"), summarise, sum = sum(CorrectedValue,
na.rm = T))
total_prop_damage <- total_prop_damage[order(total_prop_damage$sum, decreasing = T),
][1:10, ]
# Repeat the same process done above for the property damage data for the crop
# damage data
storm$CorrectedValue <- ifelse(storm$CROPDMGEXP == "H", storm$CROPDMG * 100, ifelse(storm$CROPDMGEXP ==
"K", storm$CROPDMG * 1000, ifelse(storm$CROPDMGEXP == "M", storm$CROPDMG * 1e+06,
"NA")))
storm$CorrectedValue <- as.numeric(storm$CorrectedValue)
## Warning: NAs introduced by coercion
total_crop_damage <- ddply(storm, c("EVTYPE"), summarise, sum = sum(CorrectedValue,
na.rm = T))
total_crop_damage <- total_crop_damage[order(total_crop_damage$sum, decreasing = T),
][1:10, ]
Results
Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
# Top 10 fatalities plot
a <- ggplot(total_fatalities, aes(x = reorder(EVTYPE, -sum), y = sum))
a <- a + geom_bar(stat = "identity") + geom_text(aes(label = sum), vjust = -0.3,
size = 3.5) + labs(title = "Top 10 Severe Weather Events Impact on Fatalities",
x = "Weather Event Type", y = "Total Fatalaty Count") + theme_classic() + theme(axis.text.x = element_text(angle = 90,
vjust = 0.5), plot.title = element_text(hjust = 0.5))
# Top 10 injuries plot
b <- ggplot(total_injuries, aes(x = reorder(EVTYPE, -sum), y = sum))
b <- b + geom_bar(stat = "identity") + geom_text(aes(label = sum), vjust = -0.3,
size = 3.5) + labs(title = "Top 10 Severe Weather Events Impact on Injuries",
x = "Weather Event Type", y = "Total Injury Count") + theme_classic() + theme(axis.text.x = element_text(angle = 90,
vjust = 0.5), plot.title = element_text(hjust = 0.5))
# add both plots side by side using the patchwork package
a + b

Across the United States, which types of events have the greatest economic consequences?
# Top 10 property damaging events plot
a <- ggplot(total_prop_damage, aes(x = reorder(EVTYPE, -sum), y = sum))
a <- a + geom_bar(stat = "identity") + labs(title = "Top 10 Severe Weather Events Impact on Property Damage",
x = "Weather Event Type", y = "Total Property Damage Value ($)") + theme_classic() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5), plot.title = element_text(hjust = 0.5))
# Top 10 crop damaging events plot
b <- ggplot(total_crop_damage, aes(x = reorder(EVTYPE, -sum), y = sum))
b <- b + geom_bar(stat = "identity") + labs(title = "Top 10 Severe Weather Events Impact on Crop Damage",
x = "Weather Event Type", y = "Total Crop Damage Value ($)") + theme_classic() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5), plot.title = element_text(hjust = 0.5))
# add both plots side by side using the patchwork package
a + b
