knitr::opts_chunk$set(echo = TRUE)
The objectives for this analysis were to (1) identify which types of events are the most harmful with respect to population health, and (2) which types of events have the greatest economic consequences across the United States. This analysis focused on identifying the top five causes of death and injury with respect to the storm event type. To identify the greatest financial/economic impact, the top five event types were also filtered in this dataset.
The dataset was retrieved from via this link from the Coursera course website (see https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2) and downloaded to my project’s directory. The data was loaded into R Studio using the following code. After reading in the data, the analysis approach first started off with looking at the structure and default statistics of the dataset.
Here is where I noticed that the variable of interest, EVTYPE, was in need of cleaning and consolidation (there were a total of 977 event types…yikes!) to be able to complete a comprehensive analysis and answer the project objectives. After some cleaning, total EVTYPE group was 60.
library(data.table)
## Warning: package 'data.table' was built under R version 4.2.3
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'ggplot2' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::between() masks data.table::between()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::first() masks data.table::first()
## ✖ lubridate::hour() masks data.table::hour()
## ✖ lubridate::isoweek() masks data.table::isoweek()
## ✖ dplyr::lag() masks stats::lag()
## ✖ dplyr::last() masks data.table::last()
## ✖ lubridate::mday() masks data.table::mday()
## ✖ lubridate::minute() masks data.table::minute()
## ✖ lubridate::month() masks data.table::month()
## ✖ lubridate::quarter() masks data.table::quarter()
## ✖ lubridate::second() masks data.table::second()
## ✖ purrr::transpose() masks data.table::transpose()
## ✖ lubridate::wday() masks data.table::wday()
## ✖ lubridate::week() masks data.table::week()
## ✖ lubridate::yday() masks data.table::yday()
## ✖ lubridate::year() masks data.table::year()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
storms <- read.csv('repdata_data_StormData.csv.bz2')
head(storms);str(storms)
## STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE EVTYPE
## 1 1 4/18/1950 0:00:00 0130 CST 97 MOBILE AL TORNADO
## 2 1 4/18/1950 0:00:00 0145 CST 3 BALDWIN AL TORNADO
## 3 1 2/20/1951 0:00:00 1600 CST 57 FAYETTE AL TORNADO
## 4 1 6/8/1951 0:00:00 0900 CST 89 MADISON AL TORNADO
## 5 1 11/15/1951 0:00:00 1500 CST 43 CULLMAN AL TORNADO
## 6 1 11/15/1951 0:00:00 2000 CST 77 LAUDERDALE AL TORNADO
## BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END COUNTYENDN
## 1 0 0 NA
## 2 0 0 NA
## 3 0 0 NA
## 4 0 0 NA
## 5 0 0 NA
## 6 0 0 NA
## END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES INJURIES PROPDMG
## 1 0 14.0 100 3 0 0 15 25.0
## 2 0 2.0 150 2 0 0 0 2.5
## 3 0 0.1 123 2 0 0 2 25.0
## 4 0 0.0 100 2 0 0 2 2.5
## 5 0 0.0 150 2 0 0 2 2.5
## 6 0 1.5 177 2 0 0 6 2.5
## PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE
## 1 K 0 3040 8812
## 2 K 0 3042 8755
## 3 K 0 3340 8742
## 4 K 0 3458 8626
## 5 K 0 3412 8642
## 6 K 0 3450 8748
## LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1 3051 8806 1
## 2 0 0 2
## 3 0 0 3
## 4 0 0 4
## 5 0 0 5
## 6 0 0 6
## '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 ...
summary(storms)
## STATE__ BGN_DATE BGN_TIME TIME_ZONE
## Min. : 1.0 Length:902297 Length:902297 Length:902297
## 1st Qu.:19.0 Class :character Class :character Class :character
## Median :30.0 Mode :character Mode :character Mode :character
## Mean :31.2
## 3rd Qu.:45.0
## Max. :95.0
##
## COUNTY COUNTYNAME STATE EVTYPE
## Min. : 0.0 Length:902297 Length:902297 Length:902297
## 1st Qu.: 31.0 Class :character Class :character Class :character
## Median : 75.0 Mode :character Mode :character Mode :character
## Mean :100.6
## 3rd Qu.:131.0
## Max. :873.0
##
## BGN_RANGE BGN_AZI BGN_LOCATI END_DATE
## Min. : 0.000 Length:902297 Length:902297 Length:902297
## 1st Qu.: 0.000 Class :character Class :character Class :character
## Median : 0.000 Mode :character Mode :character Mode :character
## Mean : 1.484
## 3rd Qu.: 1.000
## Max. :3749.000
##
## END_TIME COUNTY_END COUNTYENDN END_RANGE
## Length:902297 Min. :0 Mode:logical Min. : 0.0000
## Class :character 1st Qu.:0 NA's:902297 1st Qu.: 0.0000
## Mode :character Median :0 Median : 0.0000
## Mean :0 Mean : 0.9862
## 3rd Qu.:0 3rd Qu.: 0.0000
## Max. :0 Max. :925.0000
##
## END_AZI END_LOCATI LENGTH WIDTH
## Length:902297 Length:902297 Min. : 0.0000 Min. : 0.000
## Class :character Class :character 1st Qu.: 0.0000 1st Qu.: 0.000
## Mode :character Mode :character Median : 0.0000 Median : 0.000
## Mean : 0.2301 Mean : 7.503
## 3rd Qu.: 0.0000 3rd Qu.: 0.000
## Max. :2315.0000 Max. :4400.000
##
## F MAG FATALITIES INJURIES
## Min. :0.0 Min. : 0.0 Min. : 0.0000 Min. : 0.0000
## 1st Qu.:0.0 1st Qu.: 0.0 1st Qu.: 0.0000 1st Qu.: 0.0000
## Median :1.0 Median : 50.0 Median : 0.0000 Median : 0.0000
## Mean :0.9 Mean : 46.9 Mean : 0.0168 Mean : 0.1557
## 3rd Qu.:1.0 3rd Qu.: 75.0 3rd Qu.: 0.0000 3rd Qu.: 0.0000
## Max. :5.0 Max. :22000.0 Max. :583.0000 Max. :1700.0000
## NA's :843563
## PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## Min. : 0.00 Length:902297 Min. : 0.000 Length:902297
## 1st Qu.: 0.00 Class :character 1st Qu.: 0.000 Class :character
## Median : 0.00 Mode :character Median : 0.000 Mode :character
## Mean : 12.06 Mean : 1.527
## 3rd Qu.: 0.50 3rd Qu.: 0.000
## Max. :5000.00 Max. :990.000
##
## WFO STATEOFFIC ZONENAMES LATITUDE
## Length:902297 Length:902297 Length:902297 Min. : 0
## Class :character Class :character Class :character 1st Qu.:2802
## Mode :character Mode :character Mode :character Median :3540
## Mean :2875
## 3rd Qu.:4019
## Max. :9706
## NA's :47
## LONGITUDE LATITUDE_E LONGITUDE_ REMARKS
## Min. :-14451 Min. : 0 Min. :-14455 Length:902297
## 1st Qu.: 7247 1st Qu.: 0 1st Qu.: 0 Class :character
## Median : 8707 Median : 0 Median : 0 Mode :character
## Mean : 6940 Mean :1452 Mean : 3509
## 3rd Qu.: 9605 3rd Qu.:3549 3rd Qu.: 8735
## Max. : 17124 Max. :9706 Max. :106220
## NA's :40
## REFNUM
## Min. : 1
## 1st Qu.:225575
## Median :451149
## Mean :451149
## 3rd Qu.:676723
## Max. :902297
##
storms$BGN_DATE <- as.Date(storms$BGN_DATE, "%m/%d/%y")
storms$END_DATE <- as.Date(storms$END_DATE, "%m/%d/%y")
storms$year <- as.character(year(storms$BGN_DATE))
storms$EVTYPE <- trimws(storms$EVTYPE, which = "both")
storms %>% group_by(EVTYPE) %>% summarise(N = n())
## # A tibble: 977 × 2
## EVTYPE N
## <chr> <int>
## 1 ? 1
## 2 ABNORMAL WARMTH 4
## 3 ABNORMALLY DRY 2
## 4 ABNORMALLY WET 1
## 5 ACCUMULATED SNOWFALL 4
## 6 AGRICULTURAL FREEZE 6
## 7 APACHE COUNTY 1
## 8 ASTRONOMICAL HIGH TIDE 103
## 9 ASTRONOMICAL LOW TIDE 174
## 10 AVALANCE 1
## # ℹ 967 more rows
storms %>%
mutate(EVTYPE = case_when(
EVTYPE %ilike% "abnormal" ~ "unusual conditions"
,EVTYPE == "?" ~ "other"
,EVTYPE %ilike% "avalan" ~ "avalanche"
,EVTYPE %ilike% "beach" ~ "beach erosion/flood" #== "beach erosin" | EVTYPE
,EVTYPE %ilike% "bitter wind" ~ "bitter wind chill temp"
,EVTYPE %ilike% "blizzard" ~ "blizzard"
,EVTYPE %ilike% "blow-out tide" ~ "blow-out tide"
,EVTYPE %ilike% "blowing snow" ~ "blowing snow conditions"
,EVTYPE %ilike% "brush fire" ~ "brush fire"
,EVTYPE %ilike% "coastal" | EVTYPE %ilike% "cstl" ~ "coastal conditions"
,EVTYPE %ilike% "cold" ~ "cold conditions"
,EVTYPE %ilike% "cool" ~ "cool conditions"
,EVTYPE %ilike% "downburst" ~ "downburst conditions"
,EVTYPE %ilike% "drought" ~ "drought"
,EVTYPE %ilike% "dry" ~ "dry conditions"
,EVTYPE %ilike% "dust" ~ "dust conditions"
,EVTYPE %ilike% "excessive" ~ "excessive conditions"
,EVTYPE %ilike% "extreme" ~ "extreme conditions"
,EVTYPE %ilike% "flash" ~ "flash flood"
,EVTYPE %ilike% "flood" ~ "flood"
,EVTYPE %ilike% "fog" ~ "foggy"
,EVTYPE %ilike% "fire" ~ "fires"
,EVTYPE %ilike% "freeze" | EVTYPE %ilike% "freezing" ~ "freezing conditions"
,EVTYPE %ilike% "frost" ~ "frosty"
,EVTYPE %ilike% "funnel" ~ "funnel"
,EVTYPE %ilike% "glaze" ~ "glaze"
,EVTYPE %ilike% "gradient wind" ~ "gradient wind"
,EVTYPE %ilike% "gust" ~ "gust"
,EVTYPE %ilike% "hail" ~ "hail"
,EVTYPE %ilike% "heat" ~ "heat"
,EVTYPE %ilike% "precipatation" | EVTYPE %ilike% "precipitation" | EVTYPE %ilike% "heavy rain" ~ "heavy rain"
,EVTYPE %ilike% "heavy shower" | EVTYPE %ilike% "hvy rain" ~ "heavy rain"
,EVTYPE %ilike% "heavy snow" ~ "heavy snow"
,EVTYPE %ilike% "heavy surf" | EVTYPE %ilike% "swell" ~ "heavy surf"
,EVTYPE %ilike% "high wind" ~ "high wind"
,EVTYPE %ilike% "high surf" | EVTYPE == "high" ~ "high surf"
,EVTYPE %ilike% "hurricane" ~ "hurricane"
,EVTYPE %ilike% "hypothermia" ~ "hypothermia"
,EVTYPE %ilike% "ice" | EVTYPE %ilike% "icy"~ "ice"
,EVTYPE %ilike% "landslide" ~ "landslide"
,EVTYPE %ilike% "light snow" ~ "light snow"
,EVTYPE %ilike% "low temp" | EVTYPE %ilike% "low wind" ~ "low temps"
,EVTYPE %ilike% "lightning" | EVTYPE %ilike% "lightening" | EVTYPE %ilike% "lighting" | EVTYPE %ilike% "ligntning"~ "lightning"
,EVTYPE %ilike% "mud" ~ "mudslide"
,EVTYPE %ilike% "rain" ~ "rain"
,EVTYPE %ilike% "rip current" ~ "rip current"
,EVTYPE %ilike% "sleet" ~ "sleet"
,EVTYPE %ilike% "stream" ~ "stream"
,EVTYPE %ilike% "snow" ~ "snow"
,EVTYPE %ilike% "summary" ~ "other"
,EVTYPE %ilike% "thunderstorm" | EVTYPE %ilike% "thu"~ "thunderstorm" #| EVTYPE %ilike% "thunderstrom"
,EVTYPE %ilike% "tornado" | EVTYPE %ilike% "torndao" ~ "tornado"
,EVTYPE %ilike% "tropical" ~ "tropical conditions"
,EVTYPE %ilike% "tstm wind" | EVTYPE %ilike% "tstm wnd" ~ "tstm wind"
,EVTYPE %ilike% "unseasonably" ~ "unseasonable conditions"
,EVTYPE %ilike% "unusual" ~ "unusual conditions"
,EVTYPE %ilike% "urban" ~ "urban conditions"
,EVTYPE %ilike% "volcanic" ~ "volcanic"
,EVTYPE %ilike% "waterspout" | EVTYPE %ilike% "spout" ~ "waterspout"
,EVTYPE %ilike% "wet" ~ "wet conditions"
,EVTYPE %ilike% "wind" ~ "wind"
,EVTYPE %ilike% "winter" ~ "winter conditions"
,EVTYPE %ilike% "temp" ~ "temperature"
,.default = "other"
# ,.default = tolower( EVTYPE)
)) %>%
count(EVTYPE, sort = TRUE) %>% arrange(EVTYPE)
## EVTYPE n
## 1 avalanche 388
## 2 beach erosion/flood 8
## 3 bitter wind chill temp 4
## 4 blizzard 2744
## 5 blow-out tide 2
## 6 blowing snow conditions 30
## 7 brush fire 4
## 8 coastal conditions 869
## 9 cold conditions 2463
## 10 cool conditions 21
## 11 downburst conditions 4
## 12 drought 2512
## 13 dry conditions 305
## 14 dust conditions 589
## 15 excessive conditions 1719
## 16 extreme conditions 254
## 17 fires 4236
## 18 flash flood 55677
## 19 flood 26197
## 20 foggy 1882
## 21 freezing conditions 1805
## 22 frosty 60
## 23 funnel 6985
## 24 glaze 46
## 25 gradient wind 17
## 26 gust 125
## 27 hail 290398
## 28 heat 928
## 29 heavy rain 11884
## 30 heavy snow 15788
## 31 heavy surf 329
## 32 high surf 740
## 33 high wind 21921
## 34 hurricane 284
## 35 hypothermia 7
## 36 ice 2197
## 37 landslide 609
## 38 light snow 182
## 39 lightning 15776
## 40 low temps 13
## 41 mudslide 35
## 42 other 1247
## 43 rain 68
## 44 rip current 774
## 45 sleet 89
## 46 snow 1515
## 47 stream 3408
## 48 temperature 76
## 49 thunderstorm 109468
## 50 tornado 60699
## 51 tropical conditions 757
## 52 tstm wind 226201
## 53 unseasonable conditions 160
## 54 unusual conditions 23
## 55 urban conditions 6
## 56 volcanic 29
## 57 waterspout 3849
## 58 wet conditions 16
## 59 wind 4279
## 60 winter conditions 19596
Here are the code and visuals for the top 5 storm event types that caused deaths and injuries during the years, 2019-2020.
storm_casualty <- storms %>%
mutate(EVTYPE = case_when(
EVTYPE %ilike% "abnormal" ~ "unusual conditions"
,EVTYPE == "?" ~ "other"
,EVTYPE %ilike% "avalan" ~ "avalanche"
,EVTYPE %ilike% "beach" ~ "beach erosion/flood" #== "beach erosin" | EVTYPE
,EVTYPE %ilike% "bitter wind" ~ "bitter wind chill temp"
,EVTYPE %ilike% "blizzard" ~ "blizzard"
,EVTYPE %ilike% "blow-out tide" ~ "blow-out tide"
,EVTYPE %ilike% "blowing snow" ~ "blowing snow conditions"
,EVTYPE %ilike% "brush fire" ~ "brush fire"
,EVTYPE %ilike% "coastal" | EVTYPE %ilike% "cstl" ~ "coastal conditions"
,EVTYPE %ilike% "cold" ~ "cold conditions"
,EVTYPE %ilike% "cool" ~ "cool conditions"
,EVTYPE %ilike% "downburst" ~ "downburst conditions"
,EVTYPE %ilike% "drought" ~ "drought"
,EVTYPE %ilike% "dry" ~ "dry conditions"
,EVTYPE %ilike% "dust" ~ "dust conditions"
,EVTYPE %ilike% "excessive" ~ "excessive conditions"
,EVTYPE %ilike% "extreme" ~ "extreme conditions"
,EVTYPE %ilike% "flash" ~ "flash flood"
,EVTYPE %ilike% "flood" ~ "flood"
,EVTYPE %ilike% "fog" ~ "foggy"
,EVTYPE %ilike% "fire" ~ "fires"
,EVTYPE %ilike% "freeze" | EVTYPE %ilike% "freezing" ~ "freezing conditions"
,EVTYPE %ilike% "frost" ~ "frosty"
,EVTYPE %ilike% "funnel" ~ "funnel"
,EVTYPE %ilike% "glaze" ~ "glaze"
,EVTYPE %ilike% "gradient wind" ~ "gradient wind"
,EVTYPE %ilike% "gust" ~ "gust"
,EVTYPE %ilike% "hail" ~ "hail"
,EVTYPE %ilike% "heat" ~ "heat"
,EVTYPE %ilike% "precipatation" | EVTYPE %ilike% "precipitation" | EVTYPE %ilike% "heavy rain" ~ "heavy rain"
,EVTYPE %ilike% "heavy shower" | EVTYPE %ilike% "hvy rain" ~ "heavy rain"
,EVTYPE %ilike% "heavy snow" ~ "heavy snow"
,EVTYPE %ilike% "heavy surf" | EVTYPE %ilike% "swell" ~ "heavy surf"
,EVTYPE %ilike% "high wind" ~ "high wind"
,EVTYPE %ilike% "high surf" | EVTYPE == "high" ~ "high surf"
,EVTYPE %ilike% "hurricane" ~ "hurricane"
,EVTYPE %ilike% "hypothermia" ~ "hypothermia"
,EVTYPE %ilike% "ice" | EVTYPE %ilike% "icy"~ "ice"
,EVTYPE %ilike% "landslide" ~ "landslide"
,EVTYPE %ilike% "light snow" ~ "light snow"
,EVTYPE %ilike% "low temp" | EVTYPE %ilike% "low wind" ~ "low temps"
,EVTYPE %ilike% "lightning" | EVTYPE %ilike% "lightening" | EVTYPE %ilike% "lighting" | EVTYPE %ilike% "ligntning"~ "lightning"
,EVTYPE %ilike% "mud" ~ "mudslide"
,EVTYPE %ilike% "rain" ~ "rain"
,EVTYPE %ilike% "rip current" ~ "rip current"
,EVTYPE %ilike% "sleet" ~ "sleet"
,EVTYPE %ilike% "stream" ~ "stream"
,EVTYPE %ilike% "snow" ~ "snow"
,EVTYPE %ilike% "summary" ~ "other"
,EVTYPE %ilike% "thunderstorm" | EVTYPE %ilike% "thu"~ "thunderstorm" #| EVTYPE %ilike% "thunderstrom"
,EVTYPE %ilike% "tornado" | EVTYPE %ilike% "torndao" ~ "tornado"
,EVTYPE %ilike% "tropical" ~ "tropical conditions"
,EVTYPE %ilike% "tstm wind" | EVTYPE %ilike% "tstm wnd" ~ "tstm wind"
,EVTYPE %ilike% "unseasonably" ~ "unseasonable conditions"
,EVTYPE %ilike% "unusual" ~ "unusual conditions"
,EVTYPE %ilike% "urban" ~ "urban conditions"
,EVTYPE %ilike% "volcanic" ~ "volcanic"
,EVTYPE %ilike% "waterspout" | EVTYPE %ilike% "spout" ~ "waterspout"
,EVTYPE %ilike% "wet" ~ "wet conditions"
,EVTYPE %ilike% "wind" ~ "wind"
,EVTYPE %ilike% "winter" ~ "winter conditions"
,EVTYPE %ilike% "temp" ~ "temperature"
,.default = "other"
)) %>%
group_by(year,EVTYPE) %>%
summarise(tot_fatalities = sum(FATALITIES, na.rm = TRUE),
tot_injuries = sum(INJURIES, na.rm = TRUE)) %>%
select(year, EVTYPE, tot_fatalities, tot_injuries) %>%
filter(tot_fatalities !=0 & tot_injuries !=0 & !is.na(year)) %>%
arrange(desc(tot_fatalities)) %>%
# top_n(10) %>%
pivot_longer(cols = c(tot_fatalities,tot_injuries), names_to = "casualty_type", values_to = "amt")
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
storm_deaths <- storm_casualty %>%
filter(casualty_type=='tot_fatalities') %>%
top_n(5) %>% arrange( EVTYPE,year)
## Selecting by amt
storm_injuries <- storm_casualty %>%
filter(casualty_type=='tot_injuries') %>%
top_n(5) %>% arrange( EVTYPE,year)
## Selecting by amt
ggplot(data = storm_deaths, aes(year, amt)) +
geom_col(alpha = .8)+
facet_grid(.~EVTYPE)+
labs(title = "Top 5 Storm Event Type Causing Death"
, x = ""
, y = "Death Count")+
scale_y_continuous(labels = scales::comma)
ggplot(data = storm_injuries, aes(year, amt)) +
geom_col(alpha = .8)+
facet_grid(.~EVTYPE)+
labs(title = "Top 5 Storm Event Type Causing Injury"
, x = ""
, y = "Injury Count")+
scale_y_continuous(labels = scales::comma)
Here are the code and visuals for the top 5 storm event types that had the most financial/economical impact during the years, 2019-2020. The dataset had variables for property damage and crop damage. This portion of the analysis combined these two amounts to yield a total damage amount.
econ_impact <- storms %>%
mutate(
prop_dmg_amt = as.numeric( paste0(
ceiling(PROPDMG) #round up
,case_when(
PROPDMGEXP=="K"~'000'
, PROPDMGEXP=="M"~'00000'
, PROPDMGEXP=="B"~'000000'
, PROPDMGEXP=="0"~'0'
, .default ='0')))
, crop_dmg_amt = as.numeric(paste0(
ceiling(CROPDMG) #round up
,case_when(
CROPDMGEXP=="K"~'000'
, CROPDMGEXP=="M"~'00000'
, CROPDMGEXP=="B"~'000000'
, CROPDMGEXP=="0"~'0'
, .default ='0')))
, tot_dmg=prop_dmg_amt+crop_dmg_amt
, EVTYPE = case_when(
EVTYPE %ilike% "abnormal" ~ "unusual conditions"
,EVTYPE == "?" ~ "other"
,EVTYPE %ilike% "avalan" ~ "avalanche"
,EVTYPE %ilike% "beach" ~ "beach erosion/flood" #== "beach erosin" | EVTYPE
,EVTYPE %ilike% "bitter wind" ~ "bitter wind chill temp"
,EVTYPE %ilike% "blizzard" ~ "blizzard"
,EVTYPE %ilike% "blow-out tide" ~ "blow-out tide"
,EVTYPE %ilike% "blowing snow" ~ "blowing snow conditions"
,EVTYPE %ilike% "brush fire" ~ "brush fire"
,EVTYPE %ilike% "coastal" | EVTYPE %ilike% "cstl" ~ "coastal conditions"
,EVTYPE %ilike% "cold" ~ "cold conditions"
,EVTYPE %ilike% "cool" ~ "cool conditions"
,EVTYPE %ilike% "downburst" ~ "downburst conditions"
,EVTYPE %ilike% "drought" ~ "drought"
,EVTYPE %ilike% "dry" ~ "dry conditions"
,EVTYPE %ilike% "dust" ~ "dust conditions"
,EVTYPE %ilike% "excessive" ~ "excessive conditions"
,EVTYPE %ilike% "extreme" ~ "extreme conditions"
,EVTYPE %ilike% "flash" ~ "flash flood"
,EVTYPE %ilike% "flood" ~ "flood"
,EVTYPE %ilike% "fog" ~ "foggy"
,EVTYPE %ilike% "fire" ~ "fires"
,EVTYPE %ilike% "freeze" | EVTYPE %ilike% "freezing" ~ "freezing conditions"
,EVTYPE %ilike% "frost" ~ "frosty"
,EVTYPE %ilike% "funnel" ~ "funnel"
,EVTYPE %ilike% "glaze" ~ "glaze"
,EVTYPE %ilike% "gradient wind" ~ "gradient wind"
,EVTYPE %ilike% "gust" ~ "gust"
,EVTYPE %ilike% "hail" ~ "hail"
,EVTYPE %ilike% "heat" ~ "heat"
,EVTYPE %ilike% "precipatation" | EVTYPE %ilike% "precipitation" | EVTYPE %ilike% "heavy rain" ~ "heavy rain"
,EVTYPE %ilike% "heavy shower" | EVTYPE %ilike% "hvy rain" ~ "heavy rain"
,EVTYPE %ilike% "heavy snow" ~ "heavy snow"
,EVTYPE %ilike% "heavy surf" | EVTYPE %ilike% "swell" ~ "heavy surf"
,EVTYPE %ilike% "high wind" ~ "high wind"
,EVTYPE %ilike% "high surf" | EVTYPE == "high" ~ "high surf"
,EVTYPE %ilike% "hurricane" ~ "hurricane"
,EVTYPE %ilike% "hypothermia" ~ "hypothermia"
,EVTYPE %ilike% "ice" | EVTYPE %ilike% "icy"~ "ice"
,EVTYPE %ilike% "landslide" ~ "landslide"
,EVTYPE %ilike% "light snow" ~ "light snow"
,EVTYPE %ilike% "low temp" | EVTYPE %ilike% "low wind" ~ "low temps"
,EVTYPE %ilike% "lightning" | EVTYPE %ilike% "lightening" | EVTYPE %ilike% "lighting" | EVTYPE %ilike% "ligntning"~ "lightning"
,EVTYPE %ilike% "mud" ~ "mudslide"
,EVTYPE %ilike% "rain" ~ "rain"
,EVTYPE %ilike% "rip current" ~ "rip current"
,EVTYPE %ilike% "sleet" ~ "sleet"
,EVTYPE %ilike% "stream" ~ "stream"
,EVTYPE %ilike% "snow" ~ "snow"
,EVTYPE %ilike% "summary" ~ "other"
,EVTYPE %ilike% "thunderstorm" | EVTYPE %ilike% "thu"~ "thunderstorm" #| EVTYPE %ilike% "thunderstrom"
,EVTYPE %ilike% "tornado" | EVTYPE %ilike% "torndao" ~ "tornado"
,EVTYPE %ilike% "tropical" ~ "tropical conditions"
,EVTYPE %ilike% "tstm wind" | EVTYPE %ilike% "tstm wnd" ~ "tstm wind"
,EVTYPE %ilike% "unseasonably" ~ "unseasonable conditions"
,EVTYPE %ilike% "unusual" ~ "unusual conditions"
,EVTYPE %ilike% "urban" ~ "urban conditions"
,EVTYPE %ilike% "volcanic" ~ "volcanic"
,EVTYPE %ilike% "waterspout" | EVTYPE %ilike% "spout" ~ "waterspout"
,EVTYPE %ilike% "wet" ~ "wet conditions"
,EVTYPE %ilike% "wind" ~ "wind"
,EVTYPE %ilike% "winter" ~ "winter conditions"
,EVTYPE %ilike% "temp" ~ "temperature"
,.default = "other"
)
) %>%
group_by(year, EVTYPE) %>%
summarise(total_damages = sum(tot_dmg, na.rm = TRUE)) %>%
select(year, EVTYPE, total_damages) %>%
filter(total_damages !=0 & !is.na(year)) %>%
arrange(desc(total_damages))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
econ_impact_top <- econ_impact %>%
top_n(5) %>% arrange( EVTYPE,year)
## Selecting by total_damages
ggplot(data = econ_impact_top, aes(year, total_damages)) +
geom_col(alpha = .8)+
facet_grid(.~EVTYPE)+
labs(title = "Top 5 Storm Event Type by Total Damages(Property+Crop $)"
, x = ""
, y = "$ amount")+
scale_y_continuous(labels = scales::comma)