knitr::opts_chunk$set(
fig.path = "README_figs/README-"
)
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. 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. The events in the database start in the year 1950 and end in November 2011. In the earlier years of the database there are generally fewer events recorded, most likely due to a lack of good records.
Load Libraries
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.4.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(knitr)
## Warning: package 'knitr' was built under R version 3.4.2
Load data
setwd("/Users/Anna/Desktop/Coursera Data Science")
Download file of dataset
url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
download.file(url, destfile ='repdata-data-StormData.csv.bz2')
Read data
stormdata <- read.csv("repdata-data-StormData.csv.bz2")
head(stormdata)
## 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
Tornados and floods are the most damaging weather events overall.
Event types harmful to population health
Population health determined by the number of fatalties and injuries. Fatalities and injuries classified by type and then ordered.
Fatalities Data
fatalityData <- (subset(stormdata, FATALITIES > 0))[c(8, 23)]
fatalityGroupedData <- aggregate(FATALITIES ~ EVTYPE, data = fatalityData, FUN = "sum", na.rm = TRUE)
fatalityGroupedData <- fatalityGroupedData[order(fatalityGroupedData$FATALITIES, decreasing=TRUE), ]
fatalityGroupedData <- fatalityGroupedData[1:5, ]
fatalityGroupedData$EVTYPE <- factor(fatalityGroupedData$EVTYPE, levels=fatalityGroupedData$EVTYPE)
Injuries Data
injuryData <- (subset(stormdata, INJURIES > 0))[c(8, 24)]
injuryGroupedData <- aggregate(INJURIES ~ EVTYPE, data = injuryData, FUN = "sum", na.rm = TRUE)
injuryGroupedData <- injuryGroupedData[order(injuryGroupedData$INJURIES, decreasing=TRUE), ]
injuryGroupedData <- injuryGroupedData[1:5, ]
injuryGroupedData$EVTYPE <- factor(injuryGroupedData$EVTYPE, levels=injuryGroupedData$EVTYPE)
Fatalites Figure
ggplot(fatalityGroupedData, aes(x=EVTYPE, y=FATALITIES)) +
geom_bar(stat="identity") +
xlab("Types") +
ylab("Fatalities") +
ggtitle("Total Fatalities")
Injuries figure
ggplot(injuryGroupedData, aes(x=EVTYPE, y=INJURIES)) +
geom_bar(stat="identity") +
xlab("Types") +
ylab("Injuries") +
ggtitle("Total Injuries")
Event types with greatest economic impact
Economic impact measured by property and crop damage. Code converts to monitary value.
damageAmount <- function(amount, magnitude)
{
returnAmount <- 0
if (toupper(magnitude)[1]=="K")
{
returnAmount <- (amount * 1000)
}
if (toupper(magnitude)[1]=="M")
{
returnAmount <- (amount * 1000000)
}
if (toupper(magnitude)[1]=="B")
{
returnAmount <- (amount * 1000000000)
}
return(returnAmount)
}
damageData <- (subset(stormdata, PROPDMG > 0 | CROPDMG > 0))[c(8, 25, 26, 27, 28)]
damageData$DamageAmount <- ((mapply(damageAmount, damageData$PROPDMG, damageData$PROPDMGEXP)) +
(mapply(damageAmount, damageData$CROPDMG, damageData$CROPDMGEXP)))
damageGroupedData <- aggregate(DamageAmount ~ EVTYPE, data = damageData, FUN = "sum", na.rm = TRUE)
damageGroupedData <- damageGroupedData[order(damageGroupedData$DamageAmount, decreasing=TRUE), ]
damageGroupedData <- damageGroupedData[1:5, ]
damageGroupedData$EVTYPE <- factor(damageGroupedData$EVTYPE, levels=damageGroupedData$EVTYPE)
List of Top 5 weather events
head(damageGroupedData, 5)
## EVTYPE DamageAmount
## 72 FLOOD 150319678250
## 197 HURRICANE/TYPHOON 71913712800
## 354 TORNADO 57352113590
## 299 STORM SURGE 43323541000
## 116 HAIL 18758221170