Packages:

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(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(RColorBrewer)

Synposis:

The weather events have great harm on health and economics. They was the cause in a lot of deaths and injuries, and cost the country billions of dollars. After the analysis the most fetal event types were: excessive heat, tornado and flash flood. These three events resulted in more than 4000 deaths from 1996 to 2011. While tornado, flood and excessive heat were the most injurious. Regarding the economic consequences, Hurricane was the most dangerous on properties. It cost more than 15 billion dollars in the period 1996-2011. Drought was the most dangerous on crops and it cost more than 3 billion dollars in the same period.

Data Loading:

filename <- "repdata%2Fdata%2FStormData.csv.bz2"
fileURL <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
if (!file.exists(filename)){
download.file(fileURL, filename)
}
if (!file.exists("repdata%2Fdata%2FStormData.csv")) { 
unzip(filename) 
}
data <- read.csv("repdata%2Fdata%2FStormData.csv")

Data Exploration:

str(data)
## 'data.frame':    902297 obs. of  37 variables:
##  $ STATE__   : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_DATE  : chr  "4/18/1950 0:00:00" "4/18/1950 0:00:00" "2/20/1951 0:00:00" "6/8/1951 0:00:00" ...
##  $ BGN_TIME  : chr  "0130" "0145" "1600" "0900" ...
##  $ TIME_ZONE : chr  "CST" "CST" "CST" "CST" ...
##  $ COUNTY    : num  97 3 57 89 43 77 9 123 125 57 ...
##  $ COUNTYNAME: chr  "MOBILE" "BALDWIN" "FAYETTE" "MADISON" ...
##  $ STATE     : chr  "AL" "AL" "AL" "AL" ...
##  $ EVTYPE    : chr  "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
##  $ BGN_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ BGN_AZI   : chr  "" "" "" "" ...
##  $ BGN_LOCATI: chr  "" "" "" "" ...
##  $ END_DATE  : chr  "" "" "" "" ...
##  $ END_TIME  : chr  "" "" "" "" ...
##  $ COUNTY_END: num  0 0 0 0 0 0 0 0 0 0 ...
##  $ COUNTYENDN: logi  NA NA NA NA NA NA ...
##  $ END_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ END_AZI   : chr  "" "" "" "" ...
##  $ END_LOCATI: chr  "" "" "" "" ...
##  $ LENGTH    : num  14 2 0.1 0 0 1.5 1.5 0 3.3 2.3 ...
##  $ WIDTH     : num  100 150 123 100 150 177 33 33 100 100 ...
##  $ F         : int  3 2 2 2 2 2 2 1 3 3 ...
##  $ MAG       : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ FATALITIES: num  0 0 0 0 0 0 0 0 1 0 ...
##  $ INJURIES  : num  15 0 2 2 2 6 1 0 14 0 ...
##  $ PROPDMG   : num  25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
##  $ PROPDMGEXP: chr  "K" "K" "K" "K" ...
##  $ CROPDMG   : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CROPDMGEXP: chr  "" "" "" "" ...
##  $ WFO       : chr  "" "" "" "" ...
##  $ STATEOFFIC: chr  "" "" "" "" ...
##  $ ZONENAMES : chr  "" "" "" "" ...
##  $ LATITUDE  : num  3040 3042 3340 3458 3412 ...
##  $ LONGITUDE : num  8812 8755 8742 8626 8642 ...
##  $ LATITUDE_E: num  3051 0 0 0 0 ...
##  $ LONGITUDE_: num  8806 0 0 0 0 ...
##  $ REMARKS   : chr  "" "" "" "" ...
##  $ REFNUM    : num  1 2 3 4 5 6 7 8 9 10 ...
data$DATE <- as.POSIXct(data$BGN_DATE, format="%m/%d/%Y %H:%M:%OS")
length(unique(data$EVTYPE))
## [1] 985

Data Processing:

The reference to understand the data and variables is here

  1. From the exploratory analysis we noticed that all the earlier events are Tornado type. When we referred to NOAA, we found that only Tornadoes was recorded in the first 5 years. From 1955-1996 only Tornadoes, Thunderstorm Winds and Hails were recorded. After that all event types were recorded. So to make the analysis fair and meaningful, we will only consider the data recorded 1996 and after. Now I am going to subset the data:
subdata <- subset(data, DATE >= as.Date("1996-01-01") )
dim(subdata)
## [1] 653530     38
  1. The questions needed in the analysis are related to the harm on population health (fetalities and injuries) and the economical damages (to properities and crops) according to event type. So, I am going to subset the variables I need to answer the questions from the original data in order to make the cleaning and analysis faster.

The variables needed are:

EVTYPE :Event type.
FATALITIES .
INJURIES .
PROPDMG : Properity damage.
PROPDMGEXP : Properity damage exponent.
CROPDMG : Crop damage.
CROPDMGEXP : Crop damage exponent.

I will make two subsets, one for the variables related to health harm, and the other for the variables related to the economic damage.

healthVar <- c("EVTYPE", "FATALITIES", "INJURIES")
healthdata <- subdata[, healthVar]
ecoVar <- c("EVTYPE",  "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")
ecodata <- subdata[, ecoVar]
length(unique(subdata$EVTYPE))
## [1] 516
  1. The most challenging mess! According to NOAA, Event types are 48. But in our subset there is 516 Event types! most of them are typos. Now we are going to try solving this.
healthdata$EVTYPE <- tolower(healthdata$EVTYPE)
healthdata$EVTYPE <- gsub(" ", "", healthdata$EVTYPE)
healthdata <- healthdata[!grepl("[Ss]ummary",healthdata$EVTYPE),]
healthdata$EVTYPE <- gsub("marinetstm", "marinethunderstormwind", healthdata$EVTYPE)
healthdata$EVTYPE[grep("tstm", healthdata$EVTYPE)] = "thunderstormwind" 
healthdata <- healthdata[!grepl("non",healthdata$EVTYPE),]
healthdata <- healthdata[!grepl("minor",healthdata$EVTYPE),]
healthdata <- healthdata[!grepl("record",healthdata$EVTYPE),]
healthdata$EVTYPE <- gsub("temperature[s]", "", healthdata$EVTYPE)
healthdata <- healthdata[!grepl("temperature",healthdata$EVTYPE),]
healthdata$EVTYPE <- gsub("/", "", healthdata$EVTYPE)
healthdata$EVTYPE[grep("extreme", healthdata$EVTYPE)] = "extremecoldwindchill"
healthdata$EVTYPE[grep("urban", healthdata$EVTYPE)] = "flood" 
healthdata$EVTYPE[grep("sml", healthdata$EVTYPE)] = "flood" 
healthdata <- healthdata[!grepl("dry",healthdata$EVTYPE),]
healthdata$EVTYPE[grep("surf", healthdata$EVTYPE)] = "highsurf"
healthdata$EVTYPE[grep("marinethunderstormwind", healthdata$EVTYPE)] = "marinetstm"
healthdata$EVTYPE[grep("thunderstormwind", healthdata$EVTYPE)] = "tstm"
healthdata$EVTYPE[grep("thunderstorm[s]", healthdata$EVTYPE)] = "tstm"
healthdata$EVTYPE[grep("marinehail", healthdata$EVTYPE)] = "marinehal"
healthdata$EVTYPE[grep("marinehighwind", healthdata$EVTYPE)] = "marinehghwnd"
healthdata$EVTYPE[grep("marinestrongwind", healthdata$EVTYPE)] = "marinestrngwnd"
healthdata <- healthdata[!grepl("marineaccident",healthdata$EVTYPE),]
healthdata$EVTYPE <- gsub("gust[y|s]", "strong", healthdata$EVTYPE)
healthdata$EVTYPE[grep("strongwind", healthdata$EVTYPE)] = "strongwnd"
healthdata$EVTYPE[grep("windstrong", healthdata$EVTYPE)] = "strongwnd"
healthdata$EVTYPE[grep("highwind", healthdata$EVTYPE)] = "highwnd"
healthdata$EVTYPE[grep("extremecoldwindchill", healthdata$EVTYPE)] = "extremecoldwndchill"
healthdata$EVTYPE[grep("windchill", healthdata$EVTYPE)] = "coldwndchill"
healthdata$EVTYPE[grep("heavyrain", healthdata$EVTYPE)] = "heavyrain"
healthdata$EVTYPE[grep("hail", healthdata$EVTYPE)] = "hail"
healthdata <- healthdata[!grepl("wind",healthdata$EVTYPE),]
healthdata$EVTYPE[grep("effectsnow", healthdata$EVTYPE)] = "lakeeffectsnw"
healthdata$EVTYPE[grep("snow", healthdata$EVTYPE)] = "heavysnow"
healthdata$EVTYPE[grep("coast", healthdata$EVTYPE)] = "coastalflood"
healthdata$EVTYPE[grep("cst", healthdata$EVTYPE)] = "coastalflood"
healthdata$EVTYPE[grep("flashflood", healthdata$EVTYPE)] = "flashflood"
healthdata$EVTYPE[grep("riverflood", healthdata$EVTYPE)] = "coastalflood"
healthdata$EVTYPE[grep("tidalflood", healthdata$EVTYPE)] = "coastalflood"
healthdata$EVTYPE[grep("streetflood", healthdata$EVTYPE)] = "flood"
healthdata <- healthdata[!grepl("wet",healthdata$EVTYPE),]
healthdata$EVTYPE[grep("freezingfog", healthdata$EVTYPE)] = "frezingfog"
healthdata$EVTYPE[grep("freez", healthdata$EVTYPE)] = "freeze"
healthdata$EVTYPE[grep("erosion", healthdata$EVTYPE)] = "coastalflood"
healthdata$EVTYPE[grep("icy", healthdata$EVTYPE)] = "heavysnow"
healthdata$EVTYPE[grep("rain", healthdata$EVTYPE)] = "heavyrain"
healthdata$EVTYPE[grep("icejam", healthdata$EVTYPE)] = "flashflood"
healthdata$EVTYPE[grep("ice", healthdata$EVTYPE)] = "icestorm"
healthdata$EVTYPE[grep("extremecold", healthdata$EVTYPE)] = "extremecldwndchill"
healthdata$EVTYPE[grep("exessivecold", healthdata$EVTYPE)] = "extremecldwndchill"
healthdata$EVTYPE[grep("cold", healthdata$EVTYPE)] = "coldwndchill"
healthdata$EVTYPE[grep("frost", healthdata$EVTYPE)] = "freeze"
healthdata$EVTYPE[grep("winterstorm", healthdata$EVTYPE)] = "wnterstorm"
healthdata$EVTYPE[grep("winter", healthdata$EVTYPE)] = "winterweather"
healthdata$EVTYPE[grep("wintr", healthdata$EVTYPE)] = "winterweather"
healthdata <- healthdata[!grepl("land",healthdata$EVTYPE),]
healthdata$EVTYPE[grep("hurricane", healthdata$EVTYPE)] = "hurricane"
healthdata$EVTYPE[grep("burst", healthdata$EVTYPE)] = "tstm"
healthdata$EVTYPE[grep("heatwave", healthdata$EVTYPE)] = "heat"
healthdata$EVTYPE[grep("excessiveheat", healthdata$EVTYPE)] = "excessiveheat"
healthdata$EVTYPE[grep("stormsurge", healthdata$EVTYPE)] = "stormsurge"
healthdata$EVTYPE[grep("sleet", healthdata$EVTYPE)] = "sleet"
healthdata$EVTYPE[grep("((hot)|(warm))weather", healthdata$EVTYPE)] = "heat"
healthdata$EVTYPE[grep("duststorm", healthdata$EVTYPE)] = "dststorm"
healthdata$EVTYPE[grep("dust", healthdata$EVTYPE)] = "dustdevil"
healthdata$EVTYPE[grep("volcanicash", healthdata$EVTYPE)] = "volcanicash"
healthdata$EVTYPE <- gsub("tstm", "thunderstorm", healthdata$EVTYPE)
healthdata$EVTYPE[grep("hypotherm", healthdata$EVTYPE)] = "winterweather"
healthdata$EVTYPE[grep("hypertherm", healthdata$EVTYPE)] = "heat"
healthdata$EVTYPE[grep("funnel", healthdata$EVTYPE)] = "funnelcloud"
healthdata$EVTYPE[grep("spout", healthdata$EVTYPE)] = "waterspout"
healthdata$EVTYPE[grep("typhoon", healthdata$EVTYPE)] = "hurricane"
healthdata$EVTYPE[grep("highswell", healthdata$EVTYPE)] = "highsurf"
healthdata$EVTYPE[grep("(hot)|(warm)", healthdata$EVTYPE)] = "heat"
healthdata$EVTYPE[grep("densefog", healthdata$EVTYPE)] = "densefog"
healthdata$EVTYPE[grep("fire", healthdata$EVTYPE)] = "wildfire"
healthdata$EVTYPE[grep("sea", healthdata$EVTYPE)] = "highsurf"
healthdata$EVTYPE <- gsub("vog", "fog", healthdata$EVTYPE)
healthdata$EVTYPE[grep("severethunderstorm", healthdata$EVTYPE)] = "thunderstorm"
healthdata$EVTYPE[grep("cloud", healthdata$EVTYPE)] = "funnelcloud"
healthdata$EVTYPE[grep("highwater", healthdata$EVTYPE)] = "flashflood"
healthdata$EVTYPE[grep("^wnd", healthdata$EVTYPE)] = "coldwndchill"
healthdata$EVTYPE[grep("wave", healthdata$EVTYPE)] = "flashflood"
healthdata$EVTYPE[grep("tornado", healthdata$EVTYPE)] = "tornado"
healthdata$EVTYPE[grep("ripcurrent", healthdata$EVTYPE)] = "ripcurrent"
healthdata <- healthdata[!grepl("(mud)|(glaze)|(precip)|(month)|(year)|(season)|(metro)|(nosevereweather)|(dam)|(tide)|(slid)|(spell)|(remnant)|(redflag)|(lights)|(drowning)",healthdata$EVTYPE),]

ecodata$EVTYPE <- tolower(ecodata$EVTYPE)
ecodata$EVTYPE <- gsub(" ", "", ecodata$EVTYPE)
ecodata <- ecodata[!grepl("[Ss]ummary",ecodata$EVTYPE),]
ecodata$EVTYPE <- gsub("marinetstm", "marinethunderstormwind", ecodata$EVTYPE)
ecodata$EVTYPE[grep("tstm", ecodata$EVTYPE)] = "thunderstormwind" 
ecodata <- ecodata[!grepl("non",ecodata$EVTYPE),]
ecodata <- ecodata[!grepl("minor",ecodata$EVTYPE),]
ecodata <- ecodata[!grepl("record",ecodata$EVTYPE),]
ecodata$EVTYPE <- gsub("temperature[s]", "", ecodata$EVTYPE)
ecodata <- ecodata[!grepl("temperature",ecodata$EVTYPE),]
ecodata$EVTYPE <- gsub("/", "", ecodata$EVTYPE)
ecodata$EVTYPE[grep("extreme", ecodata$EVTYPE)] = "extremecoldwindchill"
ecodata$EVTYPE[grep("urban", ecodata$EVTYPE)] = "flood" 
ecodata$EVTYPE[grep("sml", ecodata$EVTYPE)] = "flood" 
ecodata <- ecodata[!grepl("dry",ecodata$EVTYPE),]
ecodata$EVTYPE[grep("surf", ecodata$EVTYPE)] = "highsurf"
ecodata$EVTYPE[grep("marinethunderstormwind", ecodata$EVTYPE)] = "marinetstm"
ecodata$EVTYPE[grep("thunderstormwind", ecodata$EVTYPE)] = "tstm"
ecodata$EVTYPE[grep("thunderstorm[s]", ecodata$EVTYPE)] = "tstm"
ecodata$EVTYPE[grep("marinehail", ecodata$EVTYPE)] = "marinehal"
ecodata$EVTYPE[grep("marinehighwind", ecodata$EVTYPE)] = "marinehghwnd"
ecodata$EVTYPE[grep("marinestrongwind", ecodata$EVTYPE)] = "marinestrngwnd"
ecodata <- ecodata[!grepl("marineaccident",ecodata$EVTYPE),]
ecodata$EVTYPE <- gsub("gust[y|s]", "strong", ecodata$EVTYPE)
ecodata$EVTYPE[grep("strongwind", ecodata$EVTYPE)] = "strongwnd"
ecodata$EVTYPE[grep("windstrong", ecodata$EVTYPE)] = "strongwnd"
ecodata$EVTYPE[grep("highwind", ecodata$EVTYPE)] = "highwnd"
ecodata$EVTYPE[grep("extremecoldwindchill", ecodata$EVTYPE)] = "extremecoldwndchill"
ecodata$EVTYPE[grep("windchill", ecodata$EVTYPE)] = "coldwndchill"
ecodata$EVTYPE[grep("heavyrain", ecodata$EVTYPE)] = "heavyrain"
ecodata$EVTYPE[grep("hail", ecodata$EVTYPE)] = "hail"
ecodata <- ecodata[!grepl("wind",ecodata$EVTYPE),]
ecodata$EVTYPE[grep("effectsnow", ecodata$EVTYPE)] = "lakeeffectsnw"
ecodata$EVTYPE[grep("snow", ecodata$EVTYPE)] = "heavysnow"
ecodata$EVTYPE[grep("coast", ecodata$EVTYPE)] = "coastalflood"
ecodata$EVTYPE[grep("cst", ecodata$EVTYPE)] = "coastalflood"
ecodata$EVTYPE[grep("flashflood", ecodata$EVTYPE)] = "flashflood"
ecodata$EVTYPE[grep("riverflood", ecodata$EVTYPE)] = "coastalflood"
ecodata$EVTYPE[grep("tidalflood", ecodata$EVTYPE)] = "coastalflood"
ecodata$EVTYPE[grep("streetflood", ecodata$EVTYPE)] = "flood"
ecodata <- ecodata[!grepl("wet",ecodata$EVTYPE),]
ecodata$EVTYPE[grep("freezingfog", ecodata$EVTYPE)] = "frezingfog"
ecodata$EVTYPE[grep("freez", ecodata$EVTYPE)] = "freeze"
ecodata$EVTYPE[grep("erosion", ecodata$EVTYPE)] = "coastalflood"
ecodata$EVTYPE[grep("icy", ecodata$EVTYPE)] = "heavysnow"
ecodata$EVTYPE[grep("rain", ecodata$EVTYPE)] = "heavyrain"
ecodata$EVTYPE[grep("icejam", ecodata$EVTYPE)] = "flashflood"
ecodata$EVTYPE[grep("ice", ecodata$EVTYPE)] = "icestorm"
ecodata$EVTYPE[grep("extremecold", ecodata$EVTYPE)] = "extremecldwndchill"
ecodata$EVTYPE[grep("exessivecold", ecodata$EVTYPE)] = "extremecldwndchill"
ecodata$EVTYPE[grep("cold", ecodata$EVTYPE)] = "coldwndchill"
ecodata$EVTYPE[grep("frost", ecodata$EVTYPE)] = "freeze"
ecodata$EVTYPE[grep("winterstorm", ecodata$EVTYPE)] = "wnterstorm"
ecodata$EVTYPE[grep("winter", ecodata$EVTYPE)] = "winterweather"
ecodata$EVTYPE[grep("wintr", ecodata$EVTYPE)] = "winterweather"
ecodata <- ecodata[!grepl("land",ecodata$EVTYPE),]
ecodata$EVTYPE[grep("hurricane", ecodata$EVTYPE)] = "hurricane"
ecodata$EVTYPE[grep("burst", ecodata$EVTYPE)] = "tstm"
ecodata$EVTYPE[grep("heatwave", ecodata$EVTYPE)] = "heat"
ecodata$EVTYPE[grep("excessiveheat", ecodata$EVTYPE)] = "excessiveheat"
ecodata$EVTYPE[grep("stormsurge", ecodata$EVTYPE)] = "stormsurge"
ecodata$EVTYPE[grep("sleet", ecodata$EVTYPE)] = "sleet"
ecodata$EVTYPE[grep("((hot)|(warm))weather", ecodata$EVTYPE)] = "heat"
ecodata$EVTYPE[grep("duststorm", ecodata$EVTYPE)] = "dststorm"
ecodata$EVTYPE[grep("dust", ecodata$EVTYPE)] = "dustdevil"
ecodata$EVTYPE[grep("volcanicash", ecodata$EVTYPE)] = "volcanicash"
ecodata$EVTYPE <- gsub("tstm", "thunderstorm", ecodata$EVTYPE)
ecodata$EVTYPE[grep("hypotherm", ecodata$EVTYPE)] = "winterweather"
ecodata$EVTYPE[grep("hypertherm", ecodata$EVTYPE)] = "heat"
ecodata$EVTYPE[grep("funnel", ecodata$EVTYPE)] = "funnelcloud"
ecodata$EVTYPE[grep("spout", ecodata$EVTYPE)] = "waterspout"
ecodata$EVTYPE[grep("typhoon", ecodata$EVTYPE)] = "hurricane"
ecodata$EVTYPE[grep("highswell", ecodata$EVTYPE)] = "highsurf"
ecodata$EVTYPE[grep("(hot)|(warm)", ecodata$EVTYPE)] = "heat"
ecodata$EVTYPE[grep("densefog", ecodata$EVTYPE)] = "densefog"
ecodata$EVTYPE[grep("fire", ecodata$EVTYPE)] = "wildfire"
ecodata$EVTYPE[grep("sea", ecodata$EVTYPE)] = "highsurf"
ecodata$EVTYPE <- gsub("vog", "fog", ecodata$EVTYPE)
ecodata$EVTYPE[grep("severethunderstorm", ecodata$EVTYPE)] = "thunderstorm"
ecodata$EVTYPE[grep("cloud", ecodata$EVTYPE)] = "funnelcloud"
ecodata$EVTYPE[grep("highwater", ecodata$EVTYPE)] = "flashflood"
ecodata$EVTYPE[grep("^wnd", ecodata$EVTYPE)] = "coldwndchill"
ecodata$EVTYPE[grep("wave", ecodata$EVTYPE)] = "flashflood"
ecodata$EVTYPE[grep("tornado", ecodata$EVTYPE)] = "tornado"
ecodata$EVTYPE[grep("ripcurrent", ecodata$EVTYPE)] = "ripcurrent"
ecodata <- ecodata[!grepl("(mud)|(glaze)|(precip)|(month)|(year)|(season)|(metro)|(nosevereweather)|(dam)|(tide)|(slid)|(spell)|(remnant)|(redflag)|(lights)|(drowning)",ecodata$EVTYPE),]

length(unique(ecodata$EVTYPE))
## [1] 49
  1. Managing the exponential values:
unique(ecodata$PROPDMGEXP)
## [1] "K" ""  "M" "B" "0"
ecodata$PROPDMGEXP <- gsub("K", 1000, ecodata$PROPDMGEXP)
ecodata$PROPDMGEXP <- gsub("M", 1000000, ecodata$PROPDMGEXP)
ecodata$PROPDMGEXP <- gsub("B", 1000000000, ecodata$PROPDMGEXP)
ecodata$PROPDMGEXP[ecodata$PROPDMGEXP==""] = 0
ecodata$PROPDMGEXP <- as.numeric(ecodata$PROPDMGEXP)

unique(ecodata$CROPDMGEXP)
## [1] "K" ""  "M" "B"
ecodata$CROPDMGEXP <- gsub("K", 1000, ecodata$CROPDMGEXP)
ecodata$CROPDMGEXP <- gsub("M", 1000000, ecodata$CROPDMGEXP)
ecodata$CROPDMGEXP <- gsub("B", 1000000000, ecodata$CROPDMGEXP)
ecodata$CROPDMGEXP[ecodata$CROPDMGEXP == ""] = 0
ecodata$CROPDMGEXP <- as.numeric(ecodata$CROPDMGEXP)

ecodatasum <- summarise(ecodata, EVTYPE, PROPDMG= PROPDMG + PROPDMGEXP, CROPDMG = CROPDMG + CROPDMGEXP)

Results:

health2 <- healthdata %>% group_by(EVTYPE) %>%
  summarise(totalfetalities  = sum(FATALITIES) ,totalinjuries= sum(INJURIES)) %>%
  arrange(desc(totalfetalities))
## `summarise()` ungrouping output (override with `.groups` argument)
#these are the most 10 fetal events:
fetal <- head(health2, 10)
rename <- c("Excessive Heat", "Tornado", "Flash Flood", "Lightening", "Rip Current", "Flood", "Thunderstorm", "Extreme Cold Wind Chill", "Heat", "High Wind")
fetal$EVTYPE = rename
fetal
## # A tibble: 10 x 3
##    EVTYPE                  totalfetalities totalinjuries
##    <chr>                             <dbl>         <dbl>
##  1 Excessive Heat                     1797          6391
##  2 Tornado                            1511         20667
##  3 Flash Flood                         890          1676
##  4 Lightening                          651          4141
##  5 Rip Current                         542           503
##  6 Flood                               442          6837
##  7 Thunderstorm                        379          5130
##  8 Extreme Cold Wind Chill             257           108
##  9 Heat                                238          1311
## 10 High Wind                           235          1083
#and these are the most 10 injurious events:
health3 <- arrange(health2, desc(totalinjuries))
injury <- head(health3, 10)
rename2 <- c("Tornado", "Flood", "Excessive Heat", "Thunderstorm", "Lightening", "Flash Flood", "Wild Fire", "Hurricane", "Heat", "Winter Storm")
injury$EVTYPE= rename2
injury
## # A tibble: 10 x 3
##    EVTYPE         totalfetalities totalinjuries
##    <chr>                    <dbl>         <dbl>
##  1 Tornado                   1511         20667
##  2 Flood                      442          6837
##  3 Excessive Heat            1797          6391
##  4 Thunderstorm               379          5130
##  5 Lightening                 651          4141
##  6 Flash Flood                890          1676
##  7 Wild Fire                   87          1458
##  8 Hurricane                  125          1328
##  9 Heat                       238          1311
## 10 Winter Storm               191          1292
col1 <- brewer.pal(49, "Spectral")
par(mfrow=c(1,2))
pie(health2$totalfetalities, c("Excessive Heat", "Tornado", "Flash Flood",  "Lightening", "Rip Current", "Flood", "Thunderstorm") ,
    col = col1, main = "Fetalities")
pie(health3$totalinjuries, c("Tornado", "Flood", "Excessive Heat", "Thunderstorm", "Lightening"), col= col1, main = "Injuries")
mtext( "The Most Harmful Events on Population Health",side = 1, outer = TRUE, cex = 1, line = -2)

eco1 <- ecodatasum %>% group_by(EVTYPE) %>% 
  summarise(totalPROPDMG= sum(PROPDMG), totalCROPDMG= sum(CROPDMG))
## `summarise()` ungrouping output (override with `.groups` argument)
eco2 <- arrange(eco1, desc(totalPROPDMG))
propdmg <- head(eco2, 10)
rename3 <- c("Hurricane/Typhoon", "Flood", "Tornado", "Storm Surge", "Flash Flood", "Wild Fire", "Hail", "High Wind", "Tropical Storm", "Thunderstorm")
propdmg$EVTYPE = rename3
eco3 <- arrange(eco1, desc(totalCROPDMG))
cropdmg <- head(eco3, 10)
rename4 <- c("Drought", "Hurricane/Typhoon", "Hail", "Flood", "Thunderstorm", "Flash Flood", "Tornado", "Freeze", "High wind", "Heavy Rain")
cropdmg$EVTYPE = rename4
#Here is the highest 10 event types regarding the cost of properity damage:
propdmg
## # A tibble: 10 x 3
##    EVTYPE            totalPROPDMG totalCROPDMG
##    <chr>                    <dbl>        <dbl>
##  1 Hurricane/Typhoon 15125084227.  1059057463.
##  2 Flood              6436917989.   326469620.
##  3 Tornado            4495242878.    84368128.
##  4 Storm Surge        3043292041.      143855 
##  5 Flash Flood        2421912628.   194400067.
##  6 Wild Fire          2222172315.    29816549.
##  7 Hail               1834771387.   596026071.
##  8 High Wind          1308033616.    57469268.
##  9 Tropical Storm     1104501808.    30395264.
## 10 Thunderstorm        943942945.   311069130.
ggplot(propdmg, aes(reorder(EVTYPE, totalPROPDMG),  totalPROPDMG / 1000000000, fill= EVTYPE))+
  geom_bar(stat="identity") + 
  coord_flip() +
  theme(legend.position = "none") +
  xlab("Event Types") +
  ylab("Total cost of properity damage in billion dollars")

#and here is the highest 10 regarding the cost of crop damage: 
cropdmg
## # A tibble: 10 x 3
##    EVTYPE            totalPROPDMG totalCROPDMG
##    <chr>                    <dbl>        <dbl>
##  1 Drought              30381094.  3137405294.
##  2 Hurricane/Typhoon 15125084227.  1059057463.
##  3 Hail               1834771387.   596026071.
##  4 Flood              6436917989.   326469620.
##  5 Thunderstorm        943942945.   311069130.
##  6 Flash Flood        2421912628.   194400067.
##  7 Tornado            4495242878.    84368128.
##  8 Freeze                8057375.    78985113.
##  9 High wind          1308033616.    57469268.
## 10 Heavy Rain           61712303.    52268238.
ggplot(cropdmg, aes(reorder(EVTYPE, totalCROPDMG),  totalCROPDMG / 1000000000 , fill= EVTYPE))+
  geom_bar(stat="identity") + 
  coord_flip() +
  theme(legend.position = "none") +
  xlab("Event Types") +
  ylab("Total cost of crop damage in billion dollars")