Synopsis

Weather conditions can have major impacts on both health and the economy, the intention of this analysis is to determine the type of weather condition that generates most of the health problems such as injuries and fatalities and also to determine which type of conditions has the higher economic impact. The analysis was generated from historic data from the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. After doing the analysis it was found that the weather condition that generates both higher fatalities and injuries is the TORNADO, while the weather conditions that generates the highest crop and property damage are DROUGHTS and FLOODS respectively.

Data Procesing

  1. First we need to load the pakages needed dplyr, R.utils and ggplot2
library(dplyr)
library(R.utils)
library(ggplot2)
library(gridExtra)
library(cowplot)
  1. Then we need to download the file to begin the analysis
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2","NOAA.csv.bz2")
bunzip2("NOAA.csv.bz2", "NOAA.csv", remove = FALSE, skip = TRUE)
dataset <- read.csv("NOAA.csv")

3.Getting the data needed for the analysis of health and weather
The analysis has two intentions determine the type of event that generates biggest health problems and the type of event that has higher cost

FataandInj<-dataset[(!is.na(dataset$FATALITIES))&(!is.na(dataset$INJURIES)),]

columnasF<-c(8,23,24)
FataandInj<-FataandInj[,columnasF]
FataandInj<-group_by(FataandInj,EVTYPE)%>%summarise(sum(INJURIES),sum(FATALITIES))
FataandInj<-FataandInj[(FataandInj$`sum(INJURIES)`!=0)|(FataandInj$`sum(FATALITIES)`!=0),]
FataandInj$Total<-FataandInj$`sum(INJURIES)`+FataandInj$`sum(FATALITIES)`
TopTenFA<-arrange(FataandInj,desc(`sum(FATALITIES)`))
TopTenFA<-head(TopTenFA,10)
TopTenINJ<-arrange(FataandInj,desc(`sum(INJURIES)`))
TopTenINJ<-head(TopTenINJ,10)
  1. Getting the data nedded to analyze the economic impact of certain weather phenomena
Econ<-dataset[(!is.na(dataset$PROPDMG))&(!is.na(dataset$CROPDMG)),]

columnasEcon<-c(8,25:28)
Econ<-Econ[,columnasEcon]
Econ$PROPDMGEXP<-ifelse(Econ$PROPDMGEXP=="K",1000,ifelse(Econ$PROPDMGEXP=="M",1000000,ifelse(Econ$PROPDMGEXP=="B",1000000000,0)))
Econ$CROPDMGEXP<-ifelse(Econ$CROPDMGEXP=="K",1000,ifelse(Econ$CROPDMGEXP=="M",1000000,ifelse(Econ$CROPDMGEXP=="B",1000000000,0)))
Econ$PropertyDamage<-Econ$PROPDMG*Econ$PROPDMGEXP
Econ$CropDamage<-Econ$CROPDMG*Econ$CROPDMGEXP
Econ<-Econ[,c(1,6,7)]
Econ<-Econ[(Econ$PropertyDamage!=0)|(Econ$CropDamage!=0),]
Econ<-group_by(Econ,EVTYPE)%>%summarise(sum(PropertyDamage),sum(CropDamage))
TOPPROP<-arrange(Econ,desc(`sum(PropertyDamage)`))
TOPPROP<-head(TOPPROP,10)
TOPCROP<-arrange(Econ,desc(`sum(CropDamage)`))
TOPCROP<-head(TOPCROP,10)

Results

Fatalities

g<-ggplot(TopTenFA,aes(y=TopTenFA$`sum(FATALITIES)`,x=TopTenFA$EVTYPE))+geom_bar(stat="identity")+labs(x="Weather Condition",y="Number of fatalities ")+theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=20))+ggtitle("Weather Conditions vs Fatalities")
g

As you can observe in the graph the weather condition that generates the highest fatalities is the Tornado by far as compare to others

Injuries

g<-ggplot(TopTenINJ,aes(y=TopTenINJ$`sum(INJURIES)`,x=TopTenINJ$EVTYPE))+geom_bar(stat="identity")+labs(x="Weather Condition",y="Number of Injuries ")+theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=20))+ggtitle("Weather Conditions vs Injuries")
g

As you can observe in the graph the weather condition that generates more injuries is the Tornado by far as compare to others
This indicates that the deadliest and the weather condition that generates most injuries is the Tornado by far

g<-ggplot(TOPPROP,aes(y=TOPPROP$`sum(PropertyDamage)`,x=TOPPROP$EVTYPE))+geom_bar(stat="identity")+labs(x="Weather Condition",y="Property Damage")+theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=20))
p<-ggplot(TOPCROP,aes(y=TOPCROP$`sum(CropDamage)`,x=TOPCROP$EVTYPE))+geom_bar(stat="identity")+labs(x="Weather Condition",y="Crop Damage")+theme(axis.text.x = element_text(angle = 90, hjust = 1),plot.title = element_text(size=20))
plot_grid(p, g,labels = c("Crop damage by Weather condition","Property damage by Weather condition"),label_size = 10)

Weather conditions that generate higher damage are Floods and Droughts for property and crops respectively