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 in order to answer two questions. This database tracks characteristics of major storms and weather events in the United States, including when and where they occur, as well as estimates of any fatalities, injuries, and property damage.
library(dplyr)
library(ggplot2)
file_name = "StromData.zip"
data_url = "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
if (!file.exists(file_name)){
download.file(url = data_url, destfile = file_name)
}
stromData<- read.csv(file_name,header = TRUE)
stromData<- tbl_df(stromData)
names(stromData)
## [1] "STATE__" "BGN_DATE" "BGN_TIME" "TIME_ZONE" "COUNTY"
## [6] "COUNTYNAME" "STATE" "EVTYPE" "BGN_RANGE" "BGN_AZI"
## [11] "BGN_LOCATI" "END_DATE" "END_TIME" "COUNTY_END" "COUNTYENDN"
## [16] "END_RANGE" "END_AZI" "END_LOCATI" "LENGTH" "WIDTH"
## [21] "F" "MAG" "FATALITIES" "INJURIES" "PROPDMG"
## [26] "PROPDMGEXP" "CROPDMG" "CROPDMGEXP" "WFO" "STATEOFFIC"
## [31] "ZONENAMES" "LATITUDE" "LONGITUDE" "LATITUDE_E" "LONGITUDE_"
## [36] "REMARKS" "REFNUM"
View(stromData)
pop.health<- stromData%>%
select(EVTYPE,FATALITIES,INJURIES)%>%
group_by(EVTYPE)%>%
summarise(Total.FATALITIES=(sum(FATALITIES)), Total.INJURIES=(sum(INJURIES)))%>%
arrange(desc(Total.FATALITIES+Total.INJURIES))
names_events <- pop.health$EVTYPE
barplot(t(pop.health[1:20,-1]), names.arg =names_events[1:20] ,
beside = T, cex.names = 0.8, las=2, col = c("red", "blue"),
main="Top Disaster Casualties")
legend("topright",c("Fatalities","Injuries"),fill=c("red","blue"),bty = "n")
#property Damage
stromData$PROPDAMAGE = 0
stromData[stromData$PROPDMGEXP == "H", ]$PROPDAMAGE = stromData[stromData$PROPDMGEXP == "H", ]$PROPDMG * 10^2
stromData[stromData$PROPDMGEXP == "K", ]$PROPDAMAGE = stromData[stromData$PROPDMGEXP == "K", ]$PROPDMG * 10^3
stromData[stromData$PROPDMGEXP == "M", ]$PROPDAMAGE = stromData[stromData$PROPDMGEXP == "M", ]$PROPDMG * 10^6
stromData[stromData$PROPDMGEXP == "B", ]$PROPDAMAGE = stromData[stromData$PROPDMGEXP == "B", ]$PROPDMG * 10^9
#CropDamage
stromData$CROPDAMAGE = 0
stromData[stromData$CROPDMGEXP == "H", ]$CROPDAMAGE = stromData[stromData$CROPDMGEXP == "H", ]$CROPDMG * 10^2
stromData[stromData$CROPDMGEXP == "K", ]$CROPDAMAGE = stromData[stromData$CROPDMGEXP == "K", ]$CROPDMG * 10^3
stromData[stromData$CROPDMGEXP == "M", ]$CROPDAMAGE = stromData[stromData$CROPDMGEXP == "M", ]$CROPDMG * 10^6
stromData[stromData$CROPDMGEXP == "B", ]$CROPDAMAGE = stromData[stromData$CROPDMGEXP == "B", ]$CROPDMG * 10^9
prop.damage<- stromData%>%
mutate(totaldamage = CROPDAMAGE+PROPDAMAGE)%>%
select(EVTYPE,totaldamage)%>%
group_by(EVTYPE)%>%
summarise(totaldamageperevent = sum(totaldamage))%>%
arrange(desc(totaldamageperevent))%>%
transmute(EVTYPE= as.factor(EVTYPE),totaldamageperevent = totaldamageperevent/10^9)
View(prop.damage)
with(prop.damage, barplot(totaldamageperevent[1:20], names.arg = EVTYPE[1:20],beside =T ,cex.names =0.8,
las =2,col="light blue",
main = "Total Property and Crop Damage by Top 20 Event Types",
ylab = "Total Damage in USD (10^9)"))