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 explores 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 basic goal of this assignment is to explore the NOAA Storm Database and answer some basic questions about severe weather events. ### Key questions to address:
Across the United States, which types of events are most harmful with respect to population health?
Across the United States, which types of events have the greatest economic consequences?
The data for this prject was obtained in the form of a comma-separated-value file compressed via the bzip2 algorithm to reduce its size and found at:
https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2
The documentation can be found at:
https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2Fpd01016005curr.pdf ### Set Required Libraries
stormdata <- read.csv("/home/pc/storm.csv.bz2", header = TRUE, sep = ",")
storm <- stormdata[c("EVTYPE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")]
str(storm)
## 'data.frame': 902297 obs. of 7 variables:
## $ EVTYPE : Factor w/ 985 levels " HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
## $ 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 ...
2 variables requires a transformation into the correct values, Property Damage (PROPDMG) and Crop Damage (CROPDMG). This is done by converting the exponent data (PROPDMGEXP and CROPDMGEXP) into numerical values and mutliplying this by the values in PROPDMG and CROPDMG.
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
##
## Attaching package: 'plyr'
## The following object is masked from 'package:purrr':
##
## compact
## The following objects are masked from 'package:dplyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
The event type will need to be cleaned with like types grouped together
storm_type <- storm %>%
mutate(evtypegrp =
ifelse(grepl("LIGHTNING|LIGNTNING", EVTYPE), "LIGHTNING",
ifelse(grepl("HAIL", EVTYPE), "HAIL",
ifelse(grepl("RAIN|FLOOD|WET|FLD", EVTYPE), "RAIN",
ifelse(grepl("SNOW|WINTER|WINTRY|BLIZZARD|SLEET|COLD|ICE|FREEZE|AVALANCHE|ICY", EVTYPE), "WINTER",
ifelse(grepl("TORNADO|FUNNEL", EVTYPE), "TORNADO",
ifelse(grepl("WIND|HURRICANE", EVTYPE), "WINDS",
ifelse(grepl("STORM|THUNDER|TSTM|TROPICAL +STORM", EVTYPE), "STORM",
ifelse(grepl("FIRE", EVTYPE), "FIRE",
ifelse(grepl("FOG|VISIBILITY|DARK|DUST", EVTYPE), "FOG",
ifelse(grepl("WAVE|SURF|SURGE|TIDE|TSUNAMI|CURRENT|SWELL", EVTYPE), "WAVE",
ifelse(grepl("HEAT|HIGH +TEMP|RECORD +TEMP|WARM|DRY", EVTYPE), "HEAT",
ifelse(grepl("VOLCAN", EVTYPE), "VOLCANO",
ifelse(grepl("DROUGHT", EVTYPE), "DROUGHT",
"OTHER")))))))))))))
)
Create a summary data frame containing for the results of the 4 different outcomes
eventsum<-storm_type %>%
group_by(evtypegrp)%>%
summarize(damage=sum(DAMAGETOTAL), property=sum(PROPDMGTOTAL), crops=sum(CROPDMGTOTAL), fatallities=sum(FATALITIES), injuries=sum(INJURIES))
Create tables with the top 10 event type for population health and plot the results
fatallities<-head(eventsum[order(eventsum$fatallities, decreasing=TRUE),],10)
injuries<-head(eventsum[order(eventsum$injuries, decreasing=TRUE),],10)
ggplot(fatallities, aes(evtypegrp,fatallities, fill=fatallities))+
geom_bar(stat = "identity")+
xlab("Event Type")+ ylab("Number of Fatalities")+
ggtitle("Total Fatalities By Event Type")+
theme(axis.text.x = element_text(angle=90)) +
expand_limits(y=c(0,6000))
ggplot(injuries, aes(evtypegrp,injuries, fill=injuries))+
geom_bar(stat = "identity")+
xlab("Event Type")+ ylab("Number of Injuries")+
ggtitle("Total Injuries By Event Type")+
theme(axis.text.x = element_text(angle=90)) +
expand_limits(y=c(0,6000))
Tornado’s have the greatest impact on population health, both in terms of Fatalities and Injuries
damage <-head(eventsum[order(eventsum$damage, decreasing=TRUE),],10)
property <- damage %>% mutate(damage_type="Property", damage_amount=property)
crops <- damage %>% mutate(damage_type="Crops", damage_amount=crops)
damage_10 <- rbind(property,crops)
ggplot(damage_10, aes(evtypegrp, damage_amount, fill=factor(damage_type))) +
geom_bar(stat = "identity") +
ylab("Economical damage 1950 - 2011") +
xlab("Event") +
scale_fill_discrete(name = "Damage") +
ggtitle ("Total Economical Damage by Event") +
theme(axis.text=element_text(size=6))
Rain causes the most economic damage to prpoerty while Drought has the most economic impact of crops