Severe weather events can result in economic and public health problems. Using the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database, we identify the chief causes of weather-related fatalities, injuries, and damage to property and crops. Data from the calendar years 1982 through 2011 (inclusive) are summarized and presented.
library(knitr);
library(dplyr);
##
## 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(lubridate);
download.file("http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", "stormData.csv.bz2")
stormData <- read.csv("stormData.csv.bz2"
,header = TRUE
,na.strings = ""
,stringsAsFactors = FALSE
);
myData <- mutate(stormData, beginDate = as.Date(BGN_DATE, "%m/%d/%Y %H:%M:%S")) %>%
mutate(dtYear = year(beginDate)) %>%
filter(dtYear > 1981) %>%
mutate(propDamage = ifelse(PROPDMGEXP=="H" | PROPDMGEXP=="h"
,PROPDMG * 100
,ifelse(PROPDMGEXP=="K" | PROPDMGEXP=="k"
,PROPDMG * 1000
,ifelse (PROPDMGEXP=="M" | PROPDMGEXP=="m"
,PROPDMG * 1000000
,ifelse (PROPDMGEXP=="B" | PROPDMGEXP=="b"
,PROPDMG * 1000000000
,0))))) %>%
mutate(cropDamage = ifelse(CROPDMGEXP=="H" | CROPDMGEXP=="h"
,CROPDMG * 100
,ifelse(CROPDMGEXP=="K" | CROPDMGEXP=="k"
,CROPDMG * 1000
,ifelse (CROPDMGEXP=="M" | CROPDMGEXP=="m"
,CROPDMG * 1000000
,ifelse (CROPDMGEXP=="B" | CROPDMGEXP=="b"
,CROPDMG * 1000000000
,0))))) %>%
group_by(EVTYPE);
byType <- summarise(myData, FATALITIES = sum(FATALITIES), INJURIES = sum(INJURIES),
propDamage = sum(propDamage), cropDamage = sum(cropDamage));
Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
# sort in ascending order and take tail to easily produce descending order charts later
fatTop10 <- arrange(byType, FATALITIES) %>%
filter(!is.na(FATALITIES)) %>%
mutate(thousFat = FATALITIES/1000) %>%
tail(10);
injTop10 <- arrange(byType, INJURIES) %>%
filter(!is.na(INJURIES)) %>%
mutate(thousInj = INJURIES/1000) %>%
tail(10);
Across the United States, which types of events have the greatest economic consequences?
# sort in ascending order and take tail to easily produce descending order charts later
pdmgTop10 <- arrange(byType, propDamage) %>%
filter(!is.na(propDamage)) %>%
mutate(millPropDmg = propDamage/1000000) %>%
tail(10);
cdmgTop10 <- arrange(byType, cropDamage) %>%
filter(!is.na(cropDamage)) %>%
mutate(millCropDmg = cropDamage/1000000) %>%
tail(10);
## is this section redundant, perhaps?
par(mfrow = c(2,1)) # stack two charts in one figure
par(las = 1) # make all label text horizontal
par(mar = c(5,9,4,2)) # increase y-axis margin.
with(
fatTop10, barplot(
thousFat, main = "Top 10 Causes of Weather-related Fatalities\nUnited States 1982 - 2011", horiz = TRUE, names.arg = EVTYPE, cex.names = 0.6, xlab = "1000's of Persons"
)
);
with(
injTop10, barplot(
thousInj, main = "Top 10 Causes of Weather-related Injuries\nUnited States 1982 - 2011", horiz = TRUE, names.arg = EVTYPE, cex.names = 0.6, xlab = "1000's of Persons"
)
);
par(mfrow = c(2,1)) # stack two charts in one figure
par(las = 1) # make all label text horizontal
par(mar = c(5,9,4,2)) # increase y-axis margin.
with(
pdmgTop10, barplot(
millPropDmg, main = "Top 10 Causes of Weather-related Property Damage\nUnited States 1982 - 2011", horiz = TRUE, names.arg = EVTYPE, cex.names = 0.6, xlab = "Millions of U.S Dollars"
)
);
with(
cdmgTop10, barplot(
millCropDmg, main = "Top 10 Causes of Weather-related Crop Damage\nUnited States 1982 - 2011", horiz = TRUE, names.arg = EVTYPE, cex.names = 0.6, xlab = "Millions of U.S Dollars"
)
);