Severe weather events like storm can cause damage to properties and living beings on earth.
This project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. 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.
The analysis of data should address the following * Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health ? * Across the United States, which types of events have the greatest economic consequences ?
library(knitr)
library(ggplot2)
if(!file.exists("stormData.csv.bz2")) {
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2",
destfile = "stormData.csv.bz2")
}
# Loading data
data <- read.csv(bzfile("stormData.csv.bz2"), sep=",", header=T)
head(data)
## STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE EVTYPE
## 1 1 4/18/1950 0:00:00 0130 CST 97 MOBILE AL TORNADO
## 2 1 4/18/1950 0:00:00 0145 CST 3 BALDWIN AL TORNADO
## 3 1 2/20/1951 0:00:00 1600 CST 57 FAYETTE AL TORNADO
## 4 1 6/8/1951 0:00:00 0900 CST 89 MADISON AL TORNADO
## 5 1 11/15/1951 0:00:00 1500 CST 43 CULLMAN AL TORNADO
## 6 1 11/15/1951 0:00:00 2000 CST 77 LAUDERDALE AL TORNADO
## BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END COUNTYENDN
## 1 0 0 NA
## 2 0 0 NA
## 3 0 0 NA
## 4 0 0 NA
## 5 0 0 NA
## 6 0 0 NA
## END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES INJURIES PROPDMG
## 1 0 14.0 100 3 0 0 15 25.0
## 2 0 2.0 150 2 0 0 0 2.5
## 3 0 0.1 123 2 0 0 2 25.0
## 4 0 0.0 100 2 0 0 2 2.5
## 5 0 0.0 150 2 0 0 2 2.5
## 6 0 1.5 177 2 0 0 6 2.5
## PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE
## 1 K 0 3040 8812
## 2 K 0 3042 8755
## 3 K 0 3340 8742
## 4 K 0 3458 8626
## 5 K 0 3412 8642
## 6 K 0 3450 8748
## LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1 3051 8806 1
## 2 0 0 2
## 3 0 0 3
## 4 0 0 4
## 5 0 0 5
## 6 0 0 6
#Creating a tidy data by subsetting the required values
tidydata <- data[,c('EVTYPE','FATALITIES','INJURIES', 'PROPDMG', 'PROPDMGEXP', 'CROPDMG', 'CROPDMGEXP')]
head(tidydata,10)
## 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
## 7 TORNADO 0 1 2.5 K 0
## 8 TORNADO 0 0 2.5 K 0
## 9 TORNADO 1 14 25.0 K 0
## 10 TORNADO 0 0 25.0 K 0
str(tidydata)
## 'data.frame': 902297 obs. of 7 variables:
## $ EVTYPE : chr "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
## $ 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: chr "K" "K" "K" "K" ...
## $ CROPDMG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ CROPDMGEXP: chr "" "" "" "" ...
Inorder to find out the damage caused We have to make use of
PROPDMG and CROPDMG which indicates the amount of property and crop damage
PROPDMGEXP and CROPDMGEXP have Unit expressed in power of 10 of the above variables (H,K,M B means Hundreds, Thousands, Millions and Billions respectively)
So have to convert them into proper units
#Converting H,K,M,B units in Property damage
tidydata$PROPDMGNUM = 0
# fill in the data with correct units
tidydata[tidydata$PROPDMGEXP == "H", ]$PROPDMGNUM = tidydata[tidydata$PROPDMGEXP == "H", ]$PROPDMG * 10^2
tidydata[tidydata$PROPDMGEXP == "K", ]$PROPDMGNUM = tidydata[tidydata$PROPDMGEXP == "K", ]$PROPDMG * 10^3
tidydata[tidydata$PROPDMGEXP == "M", ]$PROPDMGNUM = tidydata[tidydata$PROPDMGEXP == "M", ]$PROPDMG * 10^6
tidydata[tidydata$PROPDMGEXP == "B", ]$PROPDMGNUM = tidydata[tidydata$PROPDMGEXP == "B", ]$PROPDMG * 10^9
head(tidydata, 10)
## EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP PROPDMGNUM
## 1 TORNADO 0 15 25.0 K 0 25000
## 2 TORNADO 0 0 2.5 K 0 2500
## 3 TORNADO 0 2 25.0 K 0 25000
## 4 TORNADO 0 2 2.5 K 0 2500
## 5 TORNADO 0 2 2.5 K 0 2500
## 6 TORNADO 0 6 2.5 K 0 2500
## 7 TORNADO 0 1 2.5 K 0 2500
## 8 TORNADO 0 0 2.5 K 0 2500
## 9 TORNADO 1 14 25.0 K 0 25000
## 10 TORNADO 0 0 25.0 K 0 25000
#Converting H,K,M,B units in Crop damage
tidydata$CROPDMGNUM = 0
# fill in the data with correct units
tidydata[tidydata$CROPDMGEXP == "H", ]$CROPDMGNUM = tidydata[tidydata$CROPDMGEXP == "H", ]$CROPDMG * 10^2
tidydata[tidydata$CROPDMGEXP == "K", ]$CROPDMGNUM = tidydata[tidydata$CROPDMGEXP == "K", ]$CROPDMG * 10^3
tidydata[tidydata$CROPDMGEXP == "M", ]$CROPDMGNUM = tidydata[tidydata$CROPDMGEXP == "M", ]$CROPDMG * 10^6
tidydata[tidydata$CROPDMGEXP == "B", ]$CROPDMGNUM = tidydata[tidydata$CROPDMGEXP == "B", ]$CROPDMG * 10^9
Question 1: Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health ?
# ploting number of fatalities with the most harmful event type
fatalities <- aggregate(FATALITIES ~ EVTYPE, data=tidydata, sum)
fatalities <- fatalities[order(-fatalities$FATALITIES), ][1:10, ]
fatalities$EVTYPE <- factor(fatalities$EVTYPE, levels = fatalities$EVTYPE)
ggplot(fatalities, aes(x = EVTYPE, y = FATALITIES)) +
geom_bar(stat = "identity", fill = "pink", las = 3) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
xlab("Event Type") + ylab("Fatalities") + ggtitle("Number of fatalities by top 10 Weather Events")
## Warning: Ignoring unknown parameters: las
# ploting number of injuries with the most harmful event type
injuries <- aggregate(INJURIES ~ EVTYPE, data=tidydata, sum)
injuries <- injuries[order(-injuries$INJURIES), ][1:10, ]
injuries$EVTYPE <- factor(injuries$EVTYPE, levels = injuries$EVTYPE)
ggplot(injuries, aes(x = EVTYPE, y = INJURIES)) +
geom_bar(stat = "identity", fill = "pink", las = 3) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
xlab("Event Type") + ylab("Injuries") + ggtitle("Number of injuries by top 10 Weather Events")
## Warning: Ignoring unknown parameters: las
So from this we can conclude that the weather event that causes the most harm to public is Tornadoes. Because most injuries and fatalities are caused by it in United States
Question 2: Across the United States, which types of events has the greatest economic consequences?
# ploting number of damages with the most harmful event type
damages <- aggregate(PROPDMGNUM + CROPDMGNUM ~ EVTYPE, data=tidydata, sum)
names(damages) = c("EVTYPE", "TOTALDAMAGE")
damages <- damages[order(-damages$TOTALDAMAGE), ][1:10, ]
damages$EVTYPE <- factor(damages$EVTYPE, levels = damages$EVTYPE)
ggplot(damages, aes(x = EVTYPE, y = TOTALDAMAGE)) +
geom_bar(stat = "identity", fill = "pink", las = 3) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
xlab("Event Type") + ylab("Damages ($)") + ggtitle("Property & Crop Damages by top 10 Weather Events")
## Warning: Ignoring unknown parameters: las
So from this we can conclude that flood causes the greatest economic consequences