Synopsis

Storms and other severe weather events can cause both public health and economic problems for communities and municipalities. Many severe events can result in fatalities, injuries, and property damage, crop damage. In this report, severe weather events which cause poplulation injuries and fatalities in terms of number of people and also property and crop damages in terms of $ are exhibited by graphics. The most harmful weather events are given sequentially in the plots. The most harmful event in terms of population fatalities and injuries is Tornado. The most harmful event in terms of property damage is Flood and in terms of crop damage is drought.

Data Processing

setwd("C:/Users/asus/Desktop/Reproducible Research")

#Downloading Files

if(!file.exists("repdata_data_StormData.csv.bz2")){
  
  fileUrl<-"https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
  
  download.file(fileUrl,destfile="./repdata_data_StormData.csv.bz2")
}

storm<-read.csv("repdata_data_StormData.csv.bz2", header=TRUE, stringsAsFactors=FALSE) 

head(storm)
##   STATE__           BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE
## 1       1  4/18/1950 0:00:00     0130       CST     97     MOBILE    AL
## 2       1  4/18/1950 0:00:00     0145       CST      3    BALDWIN    AL
## 3       1  2/20/1951 0:00:00     1600       CST     57    FAYETTE    AL
## 4       1   6/8/1951 0:00:00     0900       CST     89    MADISON    AL
## 5       1 11/15/1951 0:00:00     1500       CST     43    CULLMAN    AL
## 6       1 11/15/1951 0:00:00     2000       CST     77 LAUDERDALE    AL
##    EVTYPE BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END
## 1 TORNADO         0                                               0
## 2 TORNADO         0                                               0
## 3 TORNADO         0                                               0
## 4 TORNADO         0                                               0
## 5 TORNADO         0                                               0
## 6 TORNADO         0                                               0
##   COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES
## 1         NA         0                      14.0   100 3   0          0
## 2         NA         0                       2.0   150 2   0          0
## 3         NA         0                       0.1   123 2   0          0
## 4         NA         0                       0.0   100 2   0          0
## 5         NA         0                       0.0   150 2   0          0
## 6         NA         0                       1.5   177 2   0          0
##   INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES
## 1       15    25.0          K       0                                    
## 2        0     2.5          K       0                                    
## 3        2    25.0          K       0                                    
## 4        2     2.5          K       0                                    
## 5        2     2.5          K       0                                    
## 6        6     2.5          K       0                                    
##   LATITUDE LONGITUDE LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1     3040      8812       3051       8806              1
## 2     3042      8755          0          0              2
## 3     3340      8742          0          0              3
## 4     3458      8626          0          0              4
## 5     3412      8642          0          0              5
## 6     3450      8748          0          0              6
#We select 7 variables and multiply PROPDMG with the numerical value of PROPDMGEXP and multiply CROPDMG with the numerical value of CROPDMGEXP.

variables<-c("EVTYPE","FATALITIES","INJURIES","PROPDMG", "PROPDMGEXP","CROPDMG","CROPDMGEXP")
storm<-storm[variables]

head(storm)
##    EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 1 TORNADO          0       15    25.0          K       0           
## 2 TORNADO          0        0     2.5          K       0           
## 3 TORNADO          0        2    25.0          K       0           
## 4 TORNADO          0        2     2.5          K       0           
## 5 TORNADO          0        2     2.5          K       0           
## 6 TORNADO          0        6     2.5          K       0
unique(storm$PROPDMGEXP)
##  [1] "K" "M" ""  "B" "m" "+" "0" "5" "6" "?" "4" "2" "3" "h" "7" "H" "-"
## [18] "1" "8"
unique(storm$CROPDMGEXP)
## [1] ""  "M" "K" "m" "B" "?" "0" "k" "2"
storm_modified<-storm%>%
  mutate(PROPDMGEXP=replace(PROPDMGEXP,PROPDMGEXP=="K"|PROPDMGEXP==3,10^3))%>%
  mutate(PROPDMGEXP=replace(PROPDMGEXP,PROPDMGEXP=="M"|PROPDMGEXP=="m"|PROPDMGEXP==6,10^6))%>%
  mutate(PROPDMGEXP=replace(PROPDMGEXP,PROPDMGEXP==""|PROPDMGEXP=="+"|PROPDMGEXP==0|PROPDMGEXP=="?"|PROPDMGEXP=="-",10^0))%>%
  mutate(PROPDMGEXP=replace(PROPDMGEXP,PROPDMGEXP=="B",10^9))%>%mutate(PROPDMGEXP=replace(PROPDMGEXP,PROPDMGEXP==5,10^5))%>%
  mutate(PROPDMGEXP=replace(PROPDMGEXP,PROPDMGEXP==4,10^4))%>%
  mutate(PROPDMGEXP=replace(PROPDMGEXP,PROPDMGEXP=="h"|PROPDMGEXP=="H"|PROPDMGEXP==2,10^2))%>%
  mutate(PROPDMGEXP=replace(PROPDMGEXP,PROPDMGEXP==7,10^7))%>%mutate(PROPDMGEXP=replace(PROPDMGEXP,PROPDMGEXP==1,10^1))%>%
  mutate(PROPDMGEXP=replace(PROPDMGEXP,PROPDMGEXP==8,10^8))%>%
  mutate(CROPDMGEXP=replace(CROPDMGEXP,CROPDMGEXP==""|CROPDMGEXP==0|CROPDMGEXP=="?",10^0))%>%
  mutate(CROPDMGEXP=replace(CROPDMGEXP,CROPDMGEXP=="M"|CROPDMGEXP=="m",10^6))%>%
  mutate(CROPDMGEXP=replace(CROPDMGEXP,CROPDMGEXP=="k"|CROPDMGEXP=="K",10^3))%>%
  mutate(CROPDMGEXP=replace(CROPDMGEXP,CROPDMGEXP=="B",10^9))%>%
  mutate(CROPDMGEXP=replace(CROPDMGEXP,CROPDMGEXP==2,10^2))
  
head(storm_modified)
##    EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 1 TORNADO          0       15    25.0       1000       0          1
## 2 TORNADO          0        0     2.5       1000       0          1
## 3 TORNADO          0        2    25.0       1000       0          1
## 4 TORNADO          0        2     2.5       1000       0          1
## 5 TORNADO          0        2     2.5       1000       0          1
## 6 TORNADO          0        6     2.5       1000       0          1
storm_modified$PROPDMGEXP<-as.numeric(storm_modified$PROPDMGEXP)
storm_modified$CROPDMGEXP<-as.numeric(storm_modified$CROPDMGEXP)


storm_final<-storm_modified%>%
  mutate(PROPDMG_FINAL=PROPDMG*PROPDMGEXP)%>%
  mutate(CROPDMG_FINAL=CROPDMG*CROPDMGEXP)%>%
  select(EVTYPE,FATALITIES,INJURIES,PROPDMG_FINAL,CROPDMG_FINAL)
  
head(storm_final)
##    EVTYPE FATALITIES INJURIES PROPDMG_FINAL CROPDMG_FINAL
## 1 TORNADO          0       15         25000             0
## 2 TORNADO          0        0          2500             0
## 3 TORNADO          0        2         25000             0
## 4 TORNADO          0        2          2500             0
## 5 TORNADO          0        2          2500             0
## 6 TORNADO          0        6          2500             0

Results

1- Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?

The most harmful 7 events are listed in terms of the sum of both injuries and fatalities. Also, the most 7 events are listed in terms of injuries and fatalities separately and given in bar plots.

storm_fatalities_injuries<-melt(storm_final,id.vars="EVTYPE",measure.vars=c("FATALITIES","INJURIES"))

storm_fatalities_injuries<-storm_fatalities_injuries%>%
  group_by(EVTYPE,variable)%>%
  summarize(total=sum(value))%>%
  group_by(EVTYPE)%>%
  mutate(population_total=sum(total))%>%
  arrange(desc(population_total))

storm_fatalities_injuries<-head(storm_fatalities_injuries,14)

storm_fatalities_injuries
## # A tibble: 14 x 4
## # Groups:   EVTYPE [7]
##    EVTYPE         variable   total population_total
##    <chr>          <fct>      <dbl>            <dbl>
##  1 TORNADO        FATALITIES  5633            96979
##  2 TORNADO        INJURIES   91346            96979
##  3 EXCESSIVE HEAT FATALITIES  1903             8428
##  4 EXCESSIVE HEAT INJURIES    6525             8428
##  5 TSTM WIND      FATALITIES   504             7461
##  6 TSTM WIND      INJURIES    6957             7461
##  7 FLOOD          FATALITIES   470             7259
##  8 FLOOD          INJURIES    6789             7259
##  9 LIGHTNING      FATALITIES   816             6046
## 10 LIGHTNING      INJURIES    5230             6046
## 11 HEAT           FATALITIES   937             3037
## 12 HEAT           INJURIES    2100             3037
## 13 FLASH FLOOD    FATALITIES   978             2755
## 14 FLASH FLOOD    INJURIES    1777             2755
p1<-ggplot(data=storm_fatalities_injuries,aes(x=(reorder(EVTYPE,population_total)),y=total,fill=variable))+
  geom_bar(stat="Identity",position=position_dodge(width = 0.9))+geom_text(aes(label=total), angle=0, size=2,check_overlap = TRUE)+
  scale_fill_brewer(palette="Dark2")+labs(x="Event Type",y="No of People Affected",title="Most Harmful Events with Respect to Population Health")+
  theme(axis.text.x = element_text(angle=45, hjust=1))



storm_fatalities<-storm_final%>%
  group_by(EVTYPE)%>%
  summarize(TOTAL_FATALITIES=sum(FATALITIES))%>%
  arrange(desc(TOTAL_FATALITIES))%>%
  top_n(7)
## Selecting by TOTAL_FATALITIES
storm_fatalities
## # A tibble: 7 x 2
##   EVTYPE         TOTAL_FATALITIES
##   <chr>                     <dbl>
## 1 TORNADO                    5633
## 2 EXCESSIVE HEAT             1903
## 3 FLASH FLOOD                 978
## 4 HEAT                        937
## 5 LIGHTNING                   816
## 6 TSTM WIND                   504
## 7 FLOOD                       470
p2<-ggplot(data=storm_fatalities,aes(x=(reorder(EVTYPE,TOTAL_FATALITIES)),y=TOTAL_FATALITIES,fill=EVTYPE))+geom_bar(stat="identity")+
  geom_text(aes(label=TOTAL_FATALITIES), angle=0, size=2,check_overlap = TRUE)+scale_fill_brewer(palette="Spectral")+
  theme(axis.text.x = element_text(angle=45, hjust=1))+labs(x="Event Type",y="No of Fatalities")
  

storm_injuries<-storm_final%>%
  group_by(EVTYPE)%>%
  summarize(TOTAL_INJURIES=sum(INJURIES))%>%
  arrange(desc(TOTAL_INJURIES))%>%
  top_n(7)
## Selecting by TOTAL_INJURIES
storm_injuries
## # A tibble: 7 x 2
##   EVTYPE         TOTAL_INJURIES
##   <chr>                   <dbl>
## 1 TORNADO                 91346
## 2 TSTM WIND                6957
## 3 FLOOD                    6789
## 4 EXCESSIVE HEAT           6525
## 5 LIGHTNING                5230
## 6 HEAT                     2100
## 7 ICE STORM                1975
p3<-ggplot(data=storm_injuries,aes(x=(reorder(EVTYPE,TOTAL_INJURIES)),y=TOTAL_INJURIES,fill=EVTYPE))+geom_bar(stat="identity")+
  geom_text(aes(label=TOTAL_INJURIES), angle=0, size=2,check_overlap = TRUE)+scale_fill_brewer(palette="Spectral")+
  theme(axis.text.x = element_text(angle=45, hjust=1))+labs(x="Event Type",y="No of Injuries")


grid.arrange(arrangeGrob(p1,ncol=1,nrow=1),arrangeGrob(p2,p3,ncol=2),heights=c(2,1.5))

#The most harmful events in terms of total population damage are tornado, excessive heat, tstm wind, flood, lightning, heat and flash flood sequentially.


#The most harmful events in terms of fatalities are tornado, excessive heat, flash flood, heat, lightning, tstm wind and flood sequentially.


#The most harmful events in terms of injuries are tornado, tstm wind, flood, excessive heat, lightning,heat and ice storm.

2- Across the United States, which types of events have the greatest economic consequences?

The most harmful 7 events for property damage (in terms of billion dollar) and crop damage (in terms of billion dollar) are given separately in bar plots.

storm_prop_crop<-melt(storm_final,id.vars="EVTYPE",measure.vars=c("PROPDMG_FINAL","CROPDMG_FINAL"))

storm_prop_crop<-storm_prop_crop%>%
  group_by(EVTYPE,variable)%>%
  summarize(total=sum(value)/10^9)%>%
  group_by(EVTYPE)%>%
  mutate(prop_and_crop_total=sum(total))%>%
  arrange(desc(prop_and_crop_total))

storm_prop_crop<-head(storm_prop_crop,14)

storm_prop_crop
## # A tibble: 14 x 4
## # Groups:   EVTYPE [7]
##    EVTYPE            variable           total prop_and_crop_total
##    <chr>             <fct>              <dbl>               <dbl>
##  1 FLOOD             PROPDMG_FINAL 145.                     150. 
##  2 FLOOD             CROPDMG_FINAL   5.66                   150. 
##  3 HURRICANE/TYPHOON PROPDMG_FINAL  69.3                     71.9
##  4 HURRICANE/TYPHOON CROPDMG_FINAL   2.61                    71.9
##  5 TORNADO           PROPDMG_FINAL  56.9                     57.4
##  6 TORNADO           CROPDMG_FINAL   0.415                   57.4
##  7 STORM SURGE       PROPDMG_FINAL  43.3                     43.3
##  8 STORM SURGE       CROPDMG_FINAL   0.000005                43.3
##  9 HAIL              PROPDMG_FINAL  15.7                     18.8
## 10 HAIL              CROPDMG_FINAL   3.03                    18.8
## 11 FLASH FLOOD       PROPDMG_FINAL  16.8                     18.2
## 12 FLASH FLOOD       CROPDMG_FINAL   1.42                    18.2
## 13 DROUGHT           PROPDMG_FINAL   1.05                    15.0
## 14 DROUGHT           CROPDMG_FINAL  14.0                     15.0
library(RColorBrewer)


storm_prop_dmg<-storm_final%>%
  group_by(EVTYPE)%>%
  summarize(TOTAL_PROP_DMG=round(sum(PROPDMG_FINAL)/10^9,1))%>%
  arrange(desc(TOTAL_PROP_DMG))%>%
  top_n(7)
## Selecting by TOTAL_PROP_DMG
p4<-ggplot(data=storm_prop_dmg,aes(x=(reorder(EVTYPE,TOTAL_PROP_DMG)),y=TOTAL_PROP_DMG,fill=EVTYPE))+geom_bar(stat="identity")+
  geom_text(aes(label=TOTAL_PROP_DMG), angle=0, size=3,check_overlap = TRUE)+scale_fill_brewer(palette="Purples")+
  theme(axis.text.x = element_text(angle=45, hjust=1))+labs(x="Event Type",y="Total Property Damage (billion $)",title="Most Harmful Events with Respect to Property Damage")

p4

#The most harmful events in property damage are flood, hurricane/typhoon, tornado, storm surge, flash flood, hail and hurricane sequentially.


storm_crop_dmg<-storm_final%>%
  group_by(EVTYPE)%>%
  summarize(TOTAL_CROP_DMG=round(sum(CROPDMG_FINAL)/10^9,2))%>%
  arrange(desc(TOTAL_CROP_DMG))%>%
  top_n(7)
## Selecting by TOTAL_CROP_DMG
p5<-ggplot(data=storm_crop_dmg,aes(x=(reorder(EVTYPE,TOTAL_CROP_DMG)),y=TOTAL_CROP_DMG,fill=EVTYPE))+geom_bar(stat="identity")+
  geom_text(aes(label=TOTAL_CROP_DMG), angle=0, size=3,check_overlap = TRUE)+scale_fill_brewer(palette="Greens")+
  theme(axis.text.x = element_text(angle=45, hjust=1))+labs(x="Event Type",y="Total Crop Damage (billion $)",title="Most Harmful Events with Respect to Crop Damage")

p5

#The most harmful events in crop damage are drought, flood, river flood, ice storm, hail, hurricane and hurricane/typhoon sequentially.