Synopsis

This report will analyze the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database to estimates of any fatalities, injuries, and property damage that caused by severe weather events. There will be also a visual interpretation of the analysis.


Data Processing

This section will gives information about all the R codes used in this analysis.


1. Loading library
library(dplyr)
library(gdata)
library(ggplot2)
2. Reading data
storm = read.csv("repdata-data-StormData.csv")
storm = tbl_df(storm)
3. Cleaning & filtering data
storm$EVTYPE = trim(tolower(storm$EVTYPE))
data = storm %>%
  select(EVTYPE, FATALITIES:CROPDMGEXP) %>%
  filter(FATALITIES > 0 | INJURIES > 0 | PROPDMG > 0 | CROPDMG > 0)
4. Get total injuries and fatalities based on event type
casualities = data %>% group_by(EVTYPE) %>%
  summarise(INJURIES = sum(INJURIES),
            FATALITIES = sum(FATALITIES))
5. Calculate total casualities(injuries + fatalities)
casualities = mutate(casualities, CASUALITIES = INJURIES + FATALITIES)
casualities = casualities %>% group_by(EVTYPE) %>%
  summarise(CASUALITIES = sum(CASUALITIES))
6. Sorting result and create top 5 of most harmful weather event
casualities = arrange(casualities, desc(CASUALITIES))
casualities.top5 = head(casualities, 5)
casualities.top5
## Source: local data frame [5 x 2]
## 
##           EVTYPE CASUALITIES
## 1        tornado       96979
## 2 excessive heat        8428
## 3      tstm wind        7461
## 4          flood        7259
## 5      lightning        6046
7. Calculate prop damage and crop damage
dmgAmount = select(data, -INJURIES, -FATALITIES)
multiplier = c("K" = 1000, "M" = 1000000, "B" = 1000000000)
dmgAmount$PROPDMGEXP = toupper(dmgAmount$PROPDMGEXP)
dmgAmount$CROPDMGEXP = toupper(dmgAmount$CROPDMGEXP)
dmgAmount = dmgAmount %>%
  mutate(TOTPROPDMG = PROPDMG * multiplier[as.character(dmgAmount$PROPDMGEXP)]) %>%
  mutate(TOTCROPDMG = CROPDMG * multiplier[as.character(dmgAmount$CROPDMGEXP)])
8. Calculate total damage (prop damage + crop damage)
dmgAmount[is.na(dmgAmount)] = 0
dmgAmount = mutate(dmgAmount, TOTDMG = TOTPROPDMG + TOTCROPDMG)
dmgAmount = dmgAmount %>% group_by(EVTYPE) %>%
  summarise(TOTDMG = sum(TOTDMG))
9. Sorting result and create top 5 events that have the greatest economic consequences (in million)
dmgAmount = arrange(dmgAmount, desc(TOTDMG))
dmgAmount.top5 = head(dmgAmount, 5)
dmgAmount.top5$TOTDMG = dmgAmount.top5$TOTDMG / 1000000
dmgAmount.top5
## Source: local data frame [5 x 2]
## 
##              EVTYPE    TOTDMG
## 1             flood 150319.68
## 2 hurricane/typhoon  71913.71
## 3           tornado  57352.11
## 4       storm surge  43323.54
## 5              hail  18758.22

Result

This section will gives a visual result of the analysis.


1. Visual report of the most harmful weather event
ggplot(casualities.top5, aes(x = reorder(EVTYPE,-CASUALITIES), y = CASUALITIES)) +
  geom_bar(stat = "identity", fill = "steelblue", color = "white") +
  ylab("Total Casualities") +
  xlab("") +
  ggtitle("Most Harmful Weather Event") +
  theme_minimal()

2. Visual report of events that have the greatest economic consequences (in million)
ggplot(dmgAmount.top5, aes(x = reorder(EVTYPE,-TOTDMG), y = TOTDMG)) +
  geom_bar(stat = "identity", fill = "steelblue", color = "white") +
  ylab("Total Damage\n(in milion)") +
  xlab("") +
  ggtitle("Greatest Economic Consequences Weather Event") +
  theme_minimal()