The goal of this analysis is to explore the NOAA Storm Database to find out which type of events are most harmful to human health and have the greatest economic consequnces.

First, let us find out the human costs by extracting FATALITIES and INJURIES Columns

library(plyr)
library(ggplot2)
library(RCurl)
## Loading required package: bitops
## Loading the data
if (!file.exists("./repdata-data-StormData.csv.bz2")) {
    stormUrl = "http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
    download.file(url = stormUrl, destfile = "./repdata-data-StormData.csv.bz2")
}

stormData <- read.csv(bzfile("repdata-data-StormData.csv.bz2"))

casualties <- aggregate(stormData$FATALITIES, by = list(stormData$EVTYPE), sum)
injuries <- aggregate(stormData$INJURIES, by = list(stormData$EVTYPE), sum)
casualties[,3] <- injuries[,2]
casualties[,4] <- (casualties[,2] + casualties[,3])
colnames(casualties) <- c("Event", "Fatalities", "Injuries", "Casualties")

casualties <- casualties[sort.list(casualties[,4], decreasing = TRUE),]
casualtiesTop <- head(casualties, 20)
# change the order of factor levels
casualtiesTop$Event <- factor(casualtiesTop$Event, levels = casualtiesTop$Event[order(-casualtiesTop$Casualties)])

g <- ggplot(casualtiesTop, aes(x = Event, y = Casualties)) + geom_bar(stat = "identity")
g + theme(axis.text.x = element_text(angle = 90, hjust = 1))

The chart above shows that tornados have caused the most casualties followed by excessive heat, thunderstorm winds and flooding.

Now we will try to find the economic costs by looking at the property and crop damage caused the events.

econDamage <- aggregate(stormData$PROPDMG, by = list(stormData$EVTYPE), sum)
cropDamage <- aggregate(stormData$CROPDMG, by = list(stormData$EVTYPE), sum)
econDamage[,3] <- cropDamage[,2]
econDamage[,4] <- econDamage[,2] + econDamage[,3]
colnames(econDamage) <- c("Event", "Property", "Crop", "Total")
econDamage <- econDamage[sort.list(econDamage[,4], decreasing = TRUE),]
econDamageTop <- head(econDamage, 20)
# change the order of factor levels
econDamageTop$Event <- factor(econDamageTop$Event, levels = econDamageTop$Event[order(-econDamageTop$Total)])

g <- ggplot(econDamageTop, aes(x = Event, y = Total)) + geom_bar(stat = "identity")
g + theme(axis.text.x = element_text(angle = 90, hjust = 1))

The chart above shows that tornados are the most economically damaging event type, followed by flash flooding, thunderstorm wind, hail, and flooding.