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, and preventing such outcomes to the extent possible is a key concern.
This project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database.
I make analysis of the top 10 events that causes major public health and economic problems for communities.
stormdata<-read.csv("stormdata.csv")
Now I am loaded the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database.
Next I checked the column names and table contents.
str(stormdata)
## 'data.frame': 902297 obs. of 37 variables:
## $ STATE__ : num 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_DATE : Factor w/ 16335 levels "1/1/1966 0:00:00",..: 6523 6523 4242 11116 2224 2224 2260 383 3980 3980 ...
## $ BGN_TIME : Factor w/ 3608 levels "00:00:00 AM",..: 272 287 2705 1683 2584 3186 242 1683 3186 3186 ...
## $ TIME_ZONE : Factor w/ 22 levels "ADT","AKS","AST",..: 7 7 7 7 7 7 7 7 7 7 ...
## $ COUNTY : num 97 3 57 89 43 77 9 123 125 57 ...
## $ COUNTYNAME: Factor w/ 29601 levels "","5NM E OF MACKINAC BRIDGE TO PRESQUE ISLE LT MI",..: 13513 1873 4598 10592 4372 10094 1973 23873 24418 4598 ...
## $ STATE : Factor w/ 72 levels "AK","AL","AM",..: 2 2 2 2 2 2 2 2 2 2 ...
## $ EVTYPE : Factor w/ 985 levels " HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
## $ BGN_RANGE : num 0 0 0 0 0 0 0 0 0 0 ...
## $ BGN_AZI : Factor w/ 35 levels ""," N"," NW",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_LOCATI: Factor w/ 54429 levels "","- 1 N Albion",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ END_DATE : Factor w/ 6663 levels "","1/1/1993 0:00:00",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ END_TIME : Factor w/ 3647 levels ""," 0900CST",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ COUNTY_END: num 0 0 0 0 0 0 0 0 0 0 ...
## $ COUNTYENDN: logi NA NA NA NA NA NA ...
## $ END_RANGE : num 0 0 0 0 0 0 0 0 0 0 ...
## $ END_AZI : Factor w/ 24 levels "","E","ENE","ESE",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ END_LOCATI: Factor w/ 34506 levels "","- .5 NNW",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ LENGTH : num 14 2 0.1 0 0 1.5 1.5 0 3.3 2.3 ...
## $ WIDTH : num 100 150 123 100 150 177 33 33 100 100 ...
## $ F : int 3 2 2 2 2 2 2 1 3 3 ...
## $ MAG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ FATALITIES: num 0 0 0 0 0 0 0 0 1 0 ...
## $ INJURIES : num 15 0 2 2 2 6 1 0 14 0 ...
## $ PROPDMG : num 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
## $ PROPDMGEXP: Factor w/ 19 levels "","-","?","+",..: 17 17 17 17 17 17 17 17 17 17 ...
## $ CROPDMG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ CROPDMGEXP: Factor w/ 9 levels "","?","0","2",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ WFO : Factor w/ 542 levels ""," CI","$AC",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ STATEOFFIC: Factor w/ 250 levels "","ALABAMA, Central",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ ZONENAMES : Factor w/ 25112 levels ""," "| __truncated__,..: 1 1 1 1 1 1 1 1 1 1 ...
## $ LATITUDE : num 3040 3042 3340 3458 3412 ...
## $ LONGITUDE : num 8812 8755 8742 8626 8642 ...
## $ LATITUDE_E: num 3051 0 0 0 0 ...
## $ LONGITUDE_: num 8806 0 0 0 0 ...
## $ REMARKS : Factor w/ 436774 levels "","-2 at Deer Park\n",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ REFNUM : num 1 2 3 4 5 6 7 8 9 10 ...
dim(stormdata)
## [1] 902297 37
I am going to survey the fatalities and injuries and list the top 20 most severe event type.
healthdamage<-subset(stormdata,select =c (EVTYPE,INJURIES,FATALITIES))
I summarise the data. Based on the event type.
summaryhealthdamage<-aggregate(cbind(INJURIES,FATALITIES)~EVTYPE,data =healthdamage,sum)
dim(summaryhealthdamage)
## [1] 985 3
summaryhealthdamage<-summaryhealthdamage[order(summaryhealthdamage$FATALITIES,summaryhealthdamage$INJURIES),]
majorhealthdamageevents<-tail(summaryhealthdamage,20)
dim(majorhealthdamageevents)
## [1] 20 3
Now we clean the data table to draw the graph.
library(data.table)
## Warning: package 'data.table' was built under R version 3.2.5
majorhealthdamageevent<-melt(majorhealthdamageevents,id="EVTYPE")
Now I draw the graph based on fatalities and injuries of the most harmful events.I add fatalities and injuries rates in one graph to easy compare.
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.2.5
ggplot(majorhealthdamageevent,aes(x=EVTYPE,y=value,fill=factor(variable)))+geom_bar(stat="identity",position="dodge")+theme(axis.text.x = element_text(angle = 90, hjust = 1))+xlab("Event Type")+ylab("Number")+ggtitle("Fatalities and Injuries Rates of Major Events")+theme(plot.title = element_text(hjust = 0.5))+scale_y_log10()
Now I will survey the economic impact of the events. There are the known symbols ,h stands for 100, k stands for 1000, m stands for 1 million and b stands for 1 billion. So I change the value. I left the 0 to 8 to same value and the other data “-”,“+”,“0”,“?” to 0. And then calculate the cost of Crop Damage and Property damage. And then summarize the data. And list the top 20 most impact on economic.
stormdata1<-stormdata[,c("EVTYPE","PROPDMG","PROPDMGEXP","CROPDMG","CROPDMGEXP")]
x <- data.frame(PROPDMGEXP = c("-","","?","+" ,0,1,2,3,4,5,6,7,8,"h","H","K","m","M","B"), expvalue = c(0,0,0,1,0,1,2,3,4,5,6,7,8,100,100,1000,1000000,1000000,1000000000))
stormdata2<-merge(stormdata1,x , by = c("PROPDMGEXP","PROPDMGEXP"))
y <- data.frame(CROPDMGEXP = c("?","",0,2,"k","K","M","m","B"),
expvalue = c(0,0,0,2,1000,1000,1000000,1000000,1000000000))
stormdata2<-merge(y, stormdata2, by = c("CROPDMGEXP","CROPDMGEXP"))
stormdata2$PRODCOST<-stormdata2$PROPDMG*stormdata2$expvalue.x
stormdata2$CROPCOST<-stormdata2$CROPDMG*stormdata2$expvalue.y
Costdamage<-subset(stormdata2,select =c (EVTYPE,PRODCOST,CROPCOST))
summary<-aggregate(cbind(PRODCOST,CROPCOST)~EVTYPE,data =Costdamage,sum)
summary<-summary[order(summary$PRODCOST,summary$CROPCOST),]
top20cost<-tail(summary,20)
And clean the data table.
library(data.table)
m<-melt(top20cost,id="EVTYPE")
Now I graph the top 20 events which is most severe.I graph the crop and property damage in the same table and it is easy to compare.
library(ggplot2)
ggplot(m,aes(x=EVTYPE,y=value,fill=factor(variable)))+geom_bar(stat="identity",position="dodge")+theme(axis.text.x = element_text(angle = 90, hjust = 1))+xlab("Event Type")+ylab("Cost")+ggtitle("Property and Crop Damage Cost of Major Events")+scale_y_log10()