#Synopsis By using the Storm Data provided by the U.S. National Oceanic and Atmospheric Administration’s database, analyses can be computed to determine the effect of the storms on health and economic factors. The most injuries and fatalities result from tornados. The weather event that costs the most in damages is from floods.

##Data Processing This code allows the data to be loaded into R.

setwd("~/Desktop/coursera")
data_all <- read.csv("~/Desktop/coursera/repdata-data-StormData.csv")
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
healthpop <- aggregate(cbind(FATALITIES,INJURIES)~EVTYPE, data = data_all, sum, na.rm = TRUE)
healthpop <- arrange(healthpop, desc(FATALITIES+INJURIES))
healthpop <- healthpop[1:10,]
healthpop
##               EVTYPE FATALITIES INJURIES
## 1            TORNADO       5633    91346
## 2     EXCESSIVE HEAT       1903     6525
## 3          TSTM WIND        504     6957
## 4              FLOOD        470     6789
## 5          LIGHTNING        816     5230
## 6               HEAT        937     2100
## 7        FLASH FLOOD        978     1777
## 8          ICE STORM         89     1975
## 9  THUNDERSTORM WIND        133     1488
## 10      WINTER STORM        206     1321

Results

barplot(t(healthpop[,-1]), names.arg=healthpop$EVTYPE, col = c("blue", "pink"), las=2, main="Harmful Storm Events") 
legend("topright", c("INJURIES","FATALITIES"), fill=c("blue", "pink"))

Tornados have the highest number of injuries and fatalities of all types of storms.

DMG_data <- data_all[, c(8, 25:28)]
#H=100s, K=1000s, M=millions, B=billions

DMG_data<-DMG_data %>% 
  mutate(PROPDMG = PROPDMG *case_when(
    PROPDMGEXP == "B" ~ 10^9,
    PROPDMGEXP == "K" ~ 10^3,
    PROPDMGEXP == "M" ~ 10^6,
    PROPDMGEXP == "H" ~ 10^2,
    TRUE ~ 0
  ), PROPDMGEXP=NULL
  )

DMG_data<-DMG_data %>%
  mutate(CROPDMG = CROPDMG *case_when(
    CROPDMGEXP == "B" ~ 10^9,
    CROPDMGEXP == "K" ~ 10^3,
    CROPDMGEXP == "M" ~ 10^6,
    CROPDMGEXP == "H" ~ 10^2,
    TRUE ~ 0
  ), CROPDMGEXP=NULL
  )
PROP_CROP <- aggregate(cbind(PROPDMG,CROPDMG) ~ EVTYPE, data_all, sum, na.rm = TRUE)
PROP_CROP <- arrange(PROP_CROP, desc(PROPDMG+CROPDMG))
PROP_CROP <- PROP_CROP[1:10, ]
PROP_CROP$PROPDMG <- PROP_CROP$PROPDMG/10^9
PROP_CROP$CROPDMG <- PROP_CROP$CROPDMG/10^9
PROP_CROP
##                EVTYPE      PROPDMG      CROPDMG
## 1             TORNADO 0.0032122582 1.000185e-04
## 2         FLASH FLOOD 0.0014201246 1.792005e-04
## 3           TSTM WIND 0.0013359656 1.092026e-04
## 4                HAIL 0.0006886934 5.795963e-04
## 5               FLOOD 0.0008999385 1.680379e-04
## 6   THUNDERSTORM WIND 0.0008768442 6.679145e-05
## 7           LIGHTNING 0.0006033518 3.580610e-06
## 8  THUNDERSTORM WINDS 0.0004462932 1.868493e-05
## 9           HIGH WIND 0.0003247316 1.728321e-05
## 10       WINTER STORM 0.0001327206 1.978990e-06
PROP_CROP_PLOT <- barplot(t(PROP_CROP[,-1]), names.arg = PROP_CROP$EVTYPE, col = c("blue", "pink"), las=2, main = "Economic Damage From Storms") 
legend("topright", c("PROPERY DMG", "CROP DMG"), fill = c("blue", "pink"))

Similar to the Harmful Storm Events, tornados have the highest overall economic damage with property and crop damage costing the most amount of money.