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. This project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database that registers this events. An exploratory analysis and graphs are presented in order to detect most harmful events.
Data load and exploring of variables and event types.
library(dplyr)
library(ggplot2)
library(gridExtra)
data<-read.csv("./repdata%2Fdata%2FStormData.csv")
head(data,3)
## 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
## 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
## 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
## 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
## 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
unique(data$EVTYPE)[1:20]
## [1] TORNADO TSTM WIND
## [3] HAIL FREEZING RAIN
## [5] SNOW ICE STORM/FLASH FLOOD
## [7] SNOW/ICE WINTER STORM
## [9] HURRICANE OPAL/HIGH WINDS THUNDERSTORM WINDS
## [11] RECORD COLD HURRICANE ERIN
## [13] HURRICANE OPAL HEAVY RAIN
## [15] LIGHTNING THUNDERSTORM WIND
## [17] DENSE FOG RIP CURRENT
## [19] THUNDERSTORM WINS FLASH FLOOD
## 985 Levels: HIGH SURF ADVISORY COASTAL FLOOD ... WND
summary(data$PROPDMGEXP)
## - ? + 0 1 2 3 4 5
## 465934 1 8 5 216 25 13 4 4 28
## 6 7 8 B h H K m M
## 4 5 1 40 1 6 424665 7 11330
summary(data$CROPDMGEXP)
## ? 0 2 B k K m M
## 618413 7 19 1 9 21 281832 1 1994
Obtaining results for fatalities and injuries.
Fatalities<-data%>%group_by(EVTYPE)%>%summarise(FATALITIES=sum(FATALITIES,na.rm=T),INJURIES=sum(INJURIES,na.rm=T))%>%arrange(desc(FATALITIES))
head(Fatalities,15)
## # A tibble: 15 × 3
## EVTYPE FATALITIES INJURIES
## <fctr> <dbl> <dbl>
## 1 TORNADO 5633 91346
## 2 EXCESSIVE HEAT 1903 6525
## 3 FLASH FLOOD 978 1777
## 4 HEAT 937 2100
## 5 LIGHTNING 816 5230
## 6 TSTM WIND 504 6957
## 7 FLOOD 470 6789
## 8 RIP CURRENT 368 232
## 9 HIGH WIND 248 1137
## 10 AVALANCHE 224 170
## 11 WINTER STORM 206 1321
## 12 RIP CURRENTS 204 297
## 13 HEAT WAVE 172 309
## 14 EXTREME COLD 160 231
## 15 THUNDERSTORM WIND 133 1488
Injuries<-data%>%group_by(EVTYPE)%>%summarise(FATALITIES=sum(FATALITIES,na.rm=T),INJURIES=sum(INJURIES,na.rm=T))%>%arrange(desc(INJURIES))
head(Injuries,15)
## # A tibble: 15 × 3
## EVTYPE FATALITIES INJURIES
## <fctr> <dbl> <dbl>
## 1 TORNADO 5633 91346
## 2 TSTM WIND 504 6957
## 3 FLOOD 470 6789
## 4 EXCESSIVE HEAT 1903 6525
## 5 LIGHTNING 816 5230
## 6 HEAT 937 2100
## 7 ICE STORM 89 1975
## 8 FLASH FLOOD 978 1777
## 9 THUNDERSTORM WIND 133 1488
## 10 HAIL 15 1361
## 11 WINTER STORM 206 1321
## 12 HURRICANE/TYPHOON 64 1275
## 13 HIGH WIND 248 1137
## 14 HEAVY SNOW 127 1021
## 15 WILDFIRE 75 911
Fatalities$EVTYPE<-factor(Fatalities$EVTYPE,levels=unique(Fatalities$EVTYPE))
Injuries$EVTYPE<-factor(Injuries$EVTYPE,levels=unique(Injuries$EVTYPE))
For property and crop damages, two variables were created in order to use the information contained in the EXP variable that has letters and numbers that represent a factor of transformation. All data with “-”, “?” and “+” were multiplied by 0 to prevent wrong interpretatinos. The numbers determined the quantity of ceros after the one to be multiplied with the damage information and letters like H, K, M and B, represented two ceros, three, six and nine respectively.
data$PROPDMGexp2<-NA
data$PROPDMGexp2[data$PROPDMGEXP=="-" | data$PROPDMGEXP=="?" | data$PROPDMGEXP=="+"]<-0
data$PROPDMGexp2[data$PROPDMGEXP=="" | data$PROPDMGEXP==0 ]<-1
data$PROPDMGexp2[data$PROPDMGEXP==1]<-10
data$PROPDMGexp2[data$PROPDMGEXP==2 | data$PROPDMGEXP=="H" | data$PROPDMGEXP=="h"]<-100
data$PROPDMGexp2[data$PROPDMGEXP==3 | data$PROPDMGEXP=="K"]<-1000
data$PROPDMGexp2[data$PROPDMGEXP==4]<-10000
data$PROPDMGexp2[data$PROPDMGEXP==5]<-100000
data$PROPDMGexp2[data$PROPDMGEXP==6 | data$PROPDMGEXP=="M" | data$PROPDMGEXP=="m"]<-1000000
data$PROPDMGexp2[data$PROPDMGEXP==7]<-10000000
data$PROPDMGexp2[data$PROPDMGEXP==8]<-100000000
data$PROPDMGexp2[data$PROPDMGEXP=="B"]<-1000000000
data$PROPDMGVal<-data$PROPDMG*data$PROPDMGexp2
data$CROPDMGexp2<-NA
data$CROPDMGexp2[data$PROPDMGEXP=="?"]<-0
data$CROPDMGexp2[data$PROPDMGEXP==0 ]<-1
data$CROPDMGexp2[data$PROPDMGEXP==2 ]<-100
data$CROPDMGexp2[data$PROPDMGEXP=="k" | data$PROPDMGEXP=="K"]<-1000
data$CROPDMGexp2[data$PROPDMGEXP=="M" | data$PROPDMGEXP=="m"]<-1000000
data$CROPDMGexp2[data$PROPDMGEXP=="B"]<-1000000000
data$CROPDMGVal<-data$CROPDMG*data$CROPDMGexp2
Tables for property and crop damages.
Property<-data%>%group_by(EVTYPE)%>%summarise(PROPDMG=sum(PROPDMGVal,na.rm=T),CROPDMG=sum(CROPDMGVal,na.rm=T))%>%arrange(desc(PROPDMG))
head(Property,15)
## # A tibble: 15 × 3
## EVTYPE PROPDMG CROPDMG
## <fctr> <dbl> <dbl>
## 1 FLOOD 144657709807 87251972270
## 2 HURRICANE/TYPHOON 69305840000 732768451330
## 3 TORNADO 56947380617 28269872233
## 4 STORM SURGE 43323536000 5000000
## 5 FLASH FLOOD 16822673979 38822137040
## 6 HAIL 15735267513 15314162250
## 7 HURRICANE 11868319010 802881916000
## 8 TROPICAL STORM 7703890550 1943517700
## 9 WINTER STORM 6688497251 688059000
## 10 HIGH WIND 5270046260 7174065610
## 11 RIVER FLOOD 5118945500 5571191000
## 12 WILDFIRE 4765114000 7173808200
## 13 STORM SURGE/TIDE 4641188000 850000
## 14 TSTM WIND 4484928495 7684639900
## 15 ICE STORM 3944927860 520416204
Crops<-data%>%group_by(EVTYPE)%>%summarise(PROPDMG=sum(PROPDMGVal,na.rm=T),CROPDMG=sum(CROPDMGVal,na.rm=T))%>%arrange(desc(CROPDMG))
head(Crops,15)
## # A tibble: 15 × 3
## EVTYPE PROPDMG CROPDMG
## <fctr> <dbl> <dbl>
## 1 HURRICANE 11868319010 802881916000
## 2 HURRICANE/TYPHOON 69305840000 732768451330
## 3 FLOOD 144657709807 87251972270
## 4 FLASH FLOOD 16822673979 38822137040
## 5 TORNADO 56947380617 28269872233
## 6 HAIL 15735267513 15314162250
## 7 HURRICANE OPAL/HIGH WINDS 100000000 10000000000
## 8 TSTM WIND 4484928495 7684639900
## 9 HIGH WIND 5270046260 7174065610
## 10 WILDFIRE 4765114000 7173808200
## 11 RIVER FLOOD 5118945500 5571191000
## 12 THUNDERSTORM WIND 3483122472 5422692550
## 13 HURRICANE OPAL 3172846000 5014000000
## 14 THUNDERSTORM WINDS 1944590859 3957223900
## 15 DROUGHT 1046106000 3443503400
Property$EVTYPE<-factor(Property$EVTYPE,levels=unique(Property$EVTYPE))
Crops$EVTYPE<-factor(Crops$EVTYPE,levels=unique(Crops$EVTYPE))
As can be seen from the graph, the event that produces most Fatalities (a) and Injuries (b) in the United States is Tornados, followed by excessive heat for both type of damages and thunderstorm wind and flood for injuries.
a1<-ggplot(Fatalities[1:15,],aes(x=EVTYPE,y=FATALITIES))+geom_bar(stat="identity")+theme(axis.text.x = element_text(angle = 45, hjust = 1))+xlab("")+ggtitle("(a) Fatalities")
a2<-ggplot(Injuries[1:15,],aes(x=EVTYPE,y=INJURIES))+geom_bar(stat="identity")+theme(axis.text.x = element_text(angle = 45, hjust = 1))+xlab("")+ggtitle("(b) Injuries")
grid.arrange(a1,a2,ncol=2,top="Weather events that produce more:")
Regarding economic consequences, Flood and Huricane/Typhoon were the events that caused highest lost in property (a) and crops (b).
b1<-ggplot(Property[1:15,],aes(x=EVTYPE,y=PROPDMG/1000000000))+geom_bar(stat="identity")+theme(axis.text.x = element_text(angle = 45, hjust = 1))+xlab("")+ggtitle("(a) Property Damage")+ylab(expression(paste("Cost of event damages (dollars x",10^9,")",sep="")))
b2<-ggplot(Crops[1:15,],aes(x=EVTYPE,y=CROPDMG/1000000000))+geom_bar(stat="identity")+theme(axis.text.x = element_text(angle = 45, hjust = 1))+xlab("")+ggtitle("(b) Crop Damage")+ylab(expression(paste("Cost of event damages (dollars x",10^9,")",sep="")))
grid.arrange(b1,b2,ncol=2,top="Weather events that produce more:")