Sypnosis

Relevent variables:
- EVTYPE: Event type.
- FATALITIES: Number of reported fatalities caused by certain weather events.
- INJURIES: Number of reported injuries caused by certain weather events.
- PROPDMG: The amount of property damage (USD) caused by certain weather events.
- CROPDMG: The amount of crop damage (USD) caused by certain weather events.

Definition:
- The most harmful to population health: causing the highest number of fatalities and injuries.
- Causing the greatest economic consequences: causing highest toll in terms of money (USD).

Data Processing

Load any relevent packages

library(ggplot2);library(tidyverse)

Load the data

fileURL <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
temporary <- tempfile(pattern = "StormData", fileext = ".csv.bz2")
download.file(fileURL, temporary, method = "curl")

StormData <- read.csv(bzfile(temporary))

unlink(temporary)

Extract the relevent variables

StormExcerpt <- select(StormData, EVTYPE,FATALITIES, INJURIES, PROPDMG, CROPDMG)

Results

Question 1: Across the US, which types of events (EVTYPE variable) are most harmful with respect to population health.

Extract top 5 events in terms of fatalities, then injuries

## Top 5 events, ranked in descending order, first with number of fatalities, then with injuries 
top5Health <- group_by(StormExcerpt,EVTYPE) %>% summarise(injuries = sum(INJURIES), fatalities = sum(FATALITIES)) %>% arrange(desc(fatalities), desc(injuries))
top5Health <- top5Health[1:5,]

## Prepare the array for ggplot
fatalities <- top5Health[,c("EVTYPE","fatalities")] %>% rename(toll = fatalities)
fatalities$type = "Dead"
injuries <- top5Health[,c("EVTYPE","injuries")] %>% rename(toll = injuries)
injuries$type = "Injured"
top5Health <- rbind(fatalities,injuries)

Graphical result

ggplot(data = top5Health, aes(y =  toll, x = EVTYPE, fill = type)) + 
  geom_bar(stat = "identity", colour = 'black') + 
  xlab("Extreme weather event type") + ylab("Number of reported cases") +
  ggtitle("Figure1. Top 5 extreme weather event types most harmful to population health")

Figure 1: The figure shows top 5 extreme weather event type causing fatalities or injuries and corresponding number of cases, dead or injured

Question 2: Across the US, which types of events have the greatest economic consequences.

Extract top 5 events in terms of property AND crop damage

## Top 5 events, ranked in descending order of economic toll (USD)
top5prop <- group_by(StormExcerpt,EVTYPE) %>% summarise(propdmg = sum(PROPDMG), cropdmg = sum(CROPDMG)) %>% arrange(desc(propdmg),desc(cropdmg))
top5prop <- top5prop[1:5,]

top5crop <- group_by(StormExcerpt,EVTYPE) %>% summarise(propdmg = sum(PROPDMG), cropdmg = sum(CROPDMG)) %>% arrange(desc(cropdmg),desc(propdmg))
top5crop <- top5crop[1:5,]

top5Economic <- full_join(x = top5crop, y =top5prop) %>% mutate(toll = propdmg + cropdmg) %>% arrange(desc(toll))
top5Economic <- top5Economic[1:5,]

## Prepare the array for ggplot
propdmg <- top5Economic[,c("EVTYPE","propdmg")] %>% rename(toll = propdmg)
propdmg$type = "property damage"
cropdmg <- top5Economic[,c("EVTYPE","cropdmg")] %>% rename(toll = cropdmg)
cropdmg$type = "crop damage"

top5Economic <- rbind(propdmg, cropdmg)

Graphical results

ggplot(data = top5Economic, aes(y = toll/1000000, x= EVTYPE, fill = type)) + 
  geom_bar(stat = "identity", colour = "black") + 
  xlab("Extreme weather event type") + ylab("Economic toll (in millions USD)") +
  ggtitle("Figure2. Top 5 extreme weather event types most harmful to the economic")

Figure 2: The figure shows top 5 extreme weather event type causing economic loss and corresponding amount of financial toll (in million USD)

Conclusion

In conclusion, tornado is considered the most harmful not only to population health but also economic health.