This report is aimed at describing severe weather events which are harmful to the population health and that have economic consequences. To analyse the events, the events which caused most fatalities, injuries and economic consequences were plotted. The data is an official publication of the National Oceanic and Atmospheric Administration (NOAA) and the documentation can be found here.
The data was downloaded from the course website, in which is also possible to download the documentation. ###Reading in the Storm Data First, the download was carried using the package downloader. Then, the file is read using the read.csv function. Turn on cache to make the process faster.
library(downloader)
## Warning: package 'downloader' was built under R version 3.1.2
download("http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", dest="stormData.csv.bz2", mode = "wb")
storm <- read.csv("stormData.csv.bz2")
Call the head to choose only the info related to the questions (event, harmful, economic consequences).
head(storm)
## 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
stormSlim <- storm[ , c("EVTYPE", "FATALITIES", "INJURIES", "PROPDMG")]
1. Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health? Aggregate the sum of injuries and the sum of fatalites per event types. Then organise them in decreasing order.
typeInjuries <- aggregate(INJURIES ~ EVTYPE, data = stormSlim, sum)
orderedInj <- typeInjuries[order(typeInjuries$INJURIES, decreasing = TRUE), ]
typeFatalities <- aggregate(FATALITIES ~ EVTYPE, data = stormSlim, sum)
orderedFat <- typeFatalities[order(typeFatalities$FATALITIES, decreasing = TRUE),]
Using ggplot, create 2 histogram of the 4 events with most fatalities and events.
library(ggplot2)
p1 <- ggplot(orderedInj[1:4, ], aes(EVTYPE, INJURIES)) + geom_bar(stat = "identity") + ylab("Injuries") + xlab("Events") + ggtitle("Most Harmful Events: Injuries")
p2 <- ggplot(orderedFat[1:4, ], aes(EVTYPE, FATALITIES)) + geom_bar(stat = "identity") + ylab("Fatalities") + xlab("Events") + ggtitle("Most Harmful Events: Fatalities")
Plot the histograms (using the package gridExtra).
library(gridExtra)
## Loading required package: grid
grid.arrange(p1, p2, nrow=2)
2. Across the United States, which types of events have the greatest economic consequences? Aggregate the sum of property damage per event types. Then organise them in decreasing order.
typeProp <- aggregate(PROPDMG ~ EVTYPE, data = stormSlim, sum)
orderedProp <- typeProp[order(typeProp$PROPDMG, decreasing = TRUE), ]
Using ggplot, create a histogram of property damage versus event types.
ggplot(orderedProp[1:4, ], aes(EVTYPE, PROPDMG)) + geom_bar(stat = "identity") + ylab("Property Damage") + xlab("Events") + ggtitle("Events X Greatest Economic Consequences")