#Title: Evaluating Harmful Environmental Events from 1950-2007: Storm Data Assignment

#Synopsis: This project involves analyzing storm data from the United States National Weather Service to identify the most harmful types of environmental events in terms of fatalities and injuries to humans, as well as economic consequences, from 1950 to 2007.

#Data Download: The storm database was downloaded from the Coursera website using the following code

library(ggplot2)
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(knitr)
StormData <- read.csv("C:/Users/sunal/OneDrive/Documents/datasciencecoursera/NewSG/Storm Data/repdata_data_StormData.csv")
View(StormData)

#Data Processing and Analysis: The United States weather data from 1950 to 2007 were analyzed by creating a subsets of data containing events that resulted in the highest fatalities, injuries, and property damage, and were summarized by event type. Events >= 20 fatalities or 200 injuries were considered high-risk to human health, and those >= $1,000 of property damange were consedered to have the greatest economic consequenses. The following code was used to create the subsets and summarize the data:

HIGH_RISK_FATALITIES <- subset(StormData, FATALITIES >=20)
HIGH_RISK_INJURIES <- subset(StormData, INJURIES >=200)
HIGH_PROPDMG <- subset(StormData, PROPDMG >= 1000)
g1plot <- ggplot(HIGH_RISK_FATALITIES, aes(x=EVTYPE, y=FATALITIES)) +    geom_bar(stat="identity", fill="red") +
labs(x="Event Type", y="Number of Fatalities", title="Fatalities by Event Type") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
g2plot <- ggplot(HIGH_RISK_INJURIES, aes(x=EVTYPE, y=INJURIES)) +
 geom_bar(stat="identity", fill="blue") +
labs(x="Event Type", y="Number of Injuries", title="Injuries by Event Type")  + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
g3plot <- ggplot(HIGH_PROPDMG, aes(x=EVTYPE, y=PROPDMG))  +
geom_bar(stat="identity", fill="green") +
labs(x="Event Type", y="Cost due to property Damage", title="Property Damage by Event Type") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
print(g1plot)

print(g2plot)

print(g3plot)

#Results From the graphs above, it is apparent that from 1950 - 2007 tornadoes, excessive heat, and flooding were the most harmful weather events to human health in the United States. Further, during this period, flash floods, thunderstorm winds, tonados, waterspouts and landslides caused the greatest property damage.