This analysis is meant to help FEMA or other emergency management agencies make more informed resource allocation decisions in order to maximize the safety of all US residents from catastrophic storms.
Part 1 findings: Across the United States, Tornados are the most harmful with respect to population health.
Part 2 findings: Across the United States, Tropical Storms have the greatest economic consequences.
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.2.4
library(plyr)
url <- 'https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2' #data location
download.file(url, 'Data/download.csv.bz2') #download data
df <- read.csv(bzfile('Data/download.csv.bz2')) #unzip and read
Summarize data
#Create count column
df$count <- 1
#Summarize by event type
df_summarized <- ddply(df, "EVTYPE", summarize,
totalDeaths = sum(FATALITIES),
count = sum(count),
propertyDamage = sum(PROPDMG),
cropDamage = sum(CROPDMG))
#Calculate the average death & damage per event
df_summarized$avgDeaths <- df_summarized$totalDeaths/df_summarized$count
df_summarized$avgDamage <- (df_summarized$propertyDamage + df_summarized$cropDamage)/df_summarized$count
#Plot most harmful events
plot <- ggplot(subset(df_summarized, avgDeaths >1 ), aes(x=reorder(factor(EVTYPE), -avgDeaths), y = avgDeaths)) +
geom_bar(stat='identity') +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
ggtitle("Average Deaths Per Top Catastrophic Event")
print(plot)
#Save plot to figures folder
png('figures/plot.png', width=1000)
plot
dev.off()
## png
## 2
#Plot most economically harmful events
plot2 <- ggplot(subset(df_summarized, avgDamage >150 ), aes(x=reorder(factor(EVTYPE), -avgDamage), y = avgDamage)) +
geom_bar(stat='identity') +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
ggtitle("Average Damage Per Top Catastrophic Event")
print(plot2)
#Save plot to figures folder
png('figures/plot.png', width=1000)
plot2
dev.off()
## png
## 2