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.
This section will gives information about all the R codes used in this analysis.
library(dplyr)
library(gdata)
library(ggplot2)
storm = read.csv("repdata-data-StormData.csv")
storm = tbl_df(storm)
storm$EVTYPE = trim(tolower(storm$EVTYPE))
data = storm %>%
select(EVTYPE, FATALITIES:CROPDMGEXP) %>%
filter(FATALITIES > 0 | INJURIES > 0 | PROPDMG > 0 | CROPDMG > 0)
casualities = data %>% group_by(EVTYPE) %>%
summarise(INJURIES = sum(INJURIES),
FATALITIES = sum(FATALITIES))
casualities = mutate(casualities, CASUALITIES = INJURIES + FATALITIES)
casualities = casualities %>% group_by(EVTYPE) %>%
summarise(CASUALITIES = sum(CASUALITIES))
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
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)])
dmgAmount[is.na(dmgAmount)] = 0
dmgAmount = mutate(dmgAmount, TOTDMG = TOTPROPDMG + TOTCROPDMG)
dmgAmount = dmgAmount %>% group_by(EVTYPE) %>%
summarise(TOTDMG = sum(TOTDMG))
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
This section will gives a visual result of the analysis.
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()
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()