June 10,2017
K.S.S SIVA TEJA
=============================================================================================
The goal of this assignment is to analyse the data and answer the required questions about severe weather events all the code that is used to analyse the database is given below
stroms and severe weather can cause a lot of damage which also includes health and economic problems for society
This project is to analyse the data from U.S Natinal oceanic and Atmospheric strom data base and understand the relations and effects of a strom including thier accurance and flatalities to property damage
1.Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health? 2.Across the United States, which types of events have the greatest economic consequences?
#reading data into r
dsn<-read.csv("C:/Users/shanmukhasri/Documents/repdata%2Fdata%2FStormData.csv")
#subseting data from data base
tidy<-dsn[,c('EVTYPE','FATALITIES','INJURIES', 'PROPDMG', 'PROPDMGEXP', 'CROPDMG', 'CROPDMGEXP')]
tidy$PROPDMGNUM = 0
tidy[tidy$PROPDMGEXP == "H", ]$PROPDMGNUM = tidy[tidy$PROPDMGEXP == "H", ]$PROPDMG * 10^2
tidy[tidy$PROPDMGEXP == "K", ]$PROPDMGNUM = tidy[tidy$PROPDMGEXP == "K", ]$PROPDMG * 10^3
tidy[tidy$PROPDMGEXP == "M", ]$PROPDMGNUM = tidy[tidy$PROPDMGEXP == "M", ]$PROPDMG * 10^6
tidy[tidy$PROPDMGEXP == "B", ]$PROPDMGNUM = tidy[tidy$PROPDMGEXP == "B", ]$PROPDMG * 10^9
tidy$CROPDMGNUM = 0
tidy[tidy$CROPDMGEXP == "H", ]$CROPDMGNUM = tidy[tidy$CROPDMGEXP == "H", ]$CROPDMG * 10^2
tidy[tidy$CROPDMGEXP == "K", ]$CROPDMGNUM = tidy[tidy$CROPDMGEXP == "K", ]$CROPDMG * 10^3
tidy[tidy$CROPDMGEXP == "M", ]$CROPDMGNUM = tidy[tidy$CROPDMGEXP == "M", ]$CROPDMG * 10^6
tidy[tidy$CROPDMGEXP == "B", ]$CROPDMGNUM = tidy[tidy$CROPDMGEXP == "B", ]$CROPDMG * 10^9
# import ggplot2 library to plot the result
library(ggplot2)
# plot number of fatalities with the most harmful event type
fatal <- aggregate(FATALITIES ~ EVTYPE, data=tidy, sum)
fatal <- fatal[order(-fatal$FATALITIES), ][1:10, ]
fatalEVTYPE <- factor(fatal$EVTYPE, levels = fatal$EVTYPE)
ggplot(fatal, aes(x = EVTYPE, y = FATALITIES)) +
geom_bar(stat = "identity", fill = "blue", las = 3) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
xlab("Event Type") + ylab("Fatalities") + ggtitle("Number of fatalities by top 10 Weather Events")
## Warning: Ignoring unknown parameters: las
# import ggplot2 library to plot the result
library(ggplot2)
# plot number of injuries with the most harmful event type
injuries <- aggregate(INJURIES ~ EVTYPE, data=tidy, sum)
injuries <- injuries[order(-injuries$INJURIES), ][1:10, ]
injuries$EVTYPE <- factor(injuries$EVTYPE, levels = injuries$EVTYPE)
ggplot(injuries, aes(x = EVTYPE, y = INJURIES)) +
geom_bar(stat = "identity", fill = "yellow", las = 3) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
xlab("Event") + ylab("Injuries") + ggtitle("Number of injuries by top 10")
## Warning: Ignoring unknown parameters: las
# import ggplot2 library to plot the result
library(ggplot2)
# plot number of damages with the most harmful event type
damages <- aggregate(PROPDMGNUM + CROPDMGNUM ~ EVTYPE, data=tidy, sum)
names(damages) = c("EVTYPE", "TOTALDAMAGE")
damages <- damages[order(-damages$TOTALDAMAGE), ][1:10, ]
damages$EVTYPE <- factor(damages$EVTYPE, levels = damages$EVTYPE)
ggplot(damages, aes(x = EVTYPE, y = TOTALDAMAGE)) +
geom_bar(stat = "identity", fill = "blue", las = 3) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
xlab("Event") + ylab("Damages") + ggtitle("Property & Crop Damages by top 10 Weather Events")
## Warning: Ignoring unknown parameters: las