U.S. National Oceanic and Atmospheric Administration’s Event Impact Analysis
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 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. The basic goal of this assignment is to explore the NOAA Storm Database and answer some basic questions about severe weather events.
Setting Working Directory and loading required packages
setwd("C:/Users/acer/Desktop/R Stuff")
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(ggplot2)
library(reshape2)
Downloading and reading data
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2","storm_data.csv.bz2")
storm_data<-read.csv("storm_data.csv.bz2")
I attempted to answer the question-Across the United States, which types of events are most harmful with respect to population health? I began with separating the data into 2 groups according to number of fatalities and injuries each event was responsible for.Here I’ve shown 2 tables comparing the number of fatalities and injuries to the event that caused them starting from the highest.
events<-group_by(storm_data,EVTYPE)
event_popn_damage<-summarise(events,Fatalities=sum(FATALITIES,na.rm=TRUE),Injuries=sum(INJURIES,na.rm=TRUE))
event_popn_damage<-mutate(event_popn_damage,Total_Dam=Fatalities+Injuries)
event_popn_damage<-arrange(event_popn_damage,-Total_Dam)
To find out which types of events have the greatest economic consequences,I subset the data by selecting out the values for property damage and crop damage caused by each event.Further ,since the damage values were some in the form of thousands,some millions and other billions ,I converted them all to numeric values.Also I separated the damage to property from the damage to crops and arranged them from highest to lowest.
#selecting out the property and crop damage from the data
event_damage<-select(storm_data,EVTYPE,PROPDMG,PROPDMGEXP,CROPDMG,CROPDMGEXP)
#Multiplying the damage values appropriately depending on whether they were stored in thousands,millions or billions
k_cond_prop<-which(event_damage$PROPDMGEXP=="K")
k_cond_crop<-which(event_damage$CROPDMGEXP=="K")
event_damage$PROPDMG[k_cond_prop]<-event_damage$PROPDMG[k_cond_prop]*1000
event_damage$CROPDMG[k_cond_crop]<-event_damage$CROPDMG[k_cond_crop]*1000
m_cond_prop<-which(event_damage$PROPDMGEXP=="M")
m_cond_crop<-which(event_damage$CROPDMGEXP=="M")
event_damage$PROPDMG[m_cond_prop]<-event_damage$PROPDMG[m_cond_prop]*10^6
event_damage$CROPDMG[m_cond_crop]<-event_damage$CROPDMG[m_cond_crop]*10^6
b_cond_prop<-which(event_damage$PROPDMGEXP=="B")
b_cond_crop<-which(event_damage$CROPDMGEXP=="B")
event_damage$PROPDMG[b_cond_prop]<-event_damage$PROPDMG[b_cond_prop]*10^9
event_damage$CROPDMG[b_cond_crop]<-event_damage$CROPDMG[b_cond_crop]*10^9
#Separating out damage to property and damage to crops and arranging them in decreasing order
grouped_damage<-group_by(event_damage,EVTYPE)
prop_dam_grouped<-summarise(grouped_damage,Property_Damage=sum(PROPDMG,na.rm=TRUE))
prop_dam_grouped<-arrange(prop_dam_grouped,-(Property_Damage))
crop_dam_grouped<-summarise(grouped_damage,Crop_Damage=sum(CROPDMG,na.rm=TRUE))
crop_dam_grouped<-arrange(crop_dam_grouped,-(Crop_Damage))
Here is a plot showing the 10 highest amount of population damage caused by events.It includes the number of fatalities and injuries per event.
meltdata<-melt(event_popn_damage[1:10,],id=c("EVTYPE"))
ggplot(meltdata)+geom_col(aes(x=reorder(EVTYPE,-value),y=value,colour=variable))+labs(x="Event Type",y="Population Damage",title="Top 10 Highest Damage to Population")+theme(axis.text.x = element_text(angle=45, hjust=1))
Here is a plot showing the 10 highest amount of property damage caused by events.
ggplot(prop_dam_grouped[1:10,])+aes(x=reorder(EVTYPE[1:10],-Property_Damage),Property_Damage[1:10])+geom_bar(stat = "identity")+labs(x="Event Type",y="Property Damage",title="10 Highest damage to Property")+theme(axis.text.x = element_text(angle=45, hjust=1))
Here is a plot showing the 10 highest amount of crop damage caused by events.
ggplot(crop_dam_grouped[1:10,])+aes(x=reorder(EVTYPE[1:10],-Crop_Damage),Crop_Damage[1:10])+geom_bar(stat = "identity")+labs(x="Event Type",y="Crop Damage",title="10 Highest damage to Crop")+theme(axis.text.x = element_text(angle=45, hjust=1))