Exploring U.S National Oceanic and Atmospheric Administration’s (NOAA) storm database from 1996 to 2011 for storm events that cause most fatalities and those that cause economic damage.
Downloading the data from the url copied from the project page.
url <- paste0("https://d396qusza40orc.cloudfront.net/",
"repdata%2Fdata%2FStormData.csv.bz2")
download.file(url, destfile = "strmData.csv.bz2")
Reading the Data
storm_data <- read.csv("strmData.csv.bz2")
dim(storm_data)
## [1] 902297 37
After reading in the data the data set has 902,297 observations and 37 variables.
After filtering the data set for variables BGN_DATE and END_DATE not
being empty strings, BGN_DATE and END_DATE are converted from character
type to Date type. A new variable called year
has been created which contains only the year from the BGN_DATE. The
data set is grouped by year and the number of observations for
each year counted.
We see that data since the year 1996 to 2011 has been very exhaustive,
hence considering the data between these years as complete and carrying
out the data exploration for the data between these years, both years
inclusive.
library(tidyverse)
## ── 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::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# changing BGN_DATE, END_DATE to Date format and creating new variable year
storm_data <- storm_data %>% filter(BGN_DATE != "", END_DATE != "") %>%
mutate(BGN_DATE = as.Date(BGN_DATE, "%m/%d/%Y"),
END_DATE = as.Date(END_DATE, "%m/%d/%Y"),
year = format(BGN_DATE, "%Y"))
# grouping by year and calculating the number of observations for each year
# start and end years for the exploration
storm_data %>%
group_by(year) %>%
summarize(n_observations = n()) %>%
arrange(desc(year))
## # A tibble: 19 × 2
## year n_observations
## <chr> <int>
## 1 2011 62174
## 2 2010 48161
## 3 2009 45817
## 4 2008 55663
## 5 2007 43289
## 6 2006 44034
## 7 2005 39184
## 8 2004 39363
## 9 2003 39752
## 10 2002 36293
## 11 2001 34962
## 12 2000 34471
## 13 1999 31289
## 14 1998 38128
## 15 1997 28680
## 16 1996 32270
## 17 1995 2906
## 18 1994 1330
## 19 1993 1120
# limiting the data to years between 1996 and 2011, both inclusive
storm_data <- storm_data %>%
filter(between(year, "1996", "2011"))
dim(storm_data)
## [1] 653530 38
Now the data set has 653,530 observations and 38 variables.
Creating a new data set by grouping by EVTYPE and summarizing the total number of injuries and fatalities occurred during these events. Determined thirteen most harmful events to population health.
injuries_and_fatalities <- storm_data %>%
filter(FATALITIES > 0, INJURIES > 0) %>%
group_by(EVTYPE) %>%
summarize(population_health = sum(INJURIES+FATALITIES)) %>%
arrange(desc(population_health))
# Storm events that are most harmful to population health
harmful_population_health <- injuries_and_fatalities %>%
.$EVTYPE
harmful_population_health
## [1] "TORNADO" "EXCESSIVE HEAT"
## [3] "FLOOD" "HURRICANE/TYPHOON"
## [5] "FLASH FLOOD" "HEAT"
## [7] "LIGHTNING" "WINTER STORM"
## [9] "TSTM WIND" "HIGH WIND"
## [11] "FOG" "BLIZZARD"
## [13] "WILDFIRE" "TROPICAL STORM"
## [15] "HEAVY SNOW" "WINTER WEATHER"
## [17] "THUNDERSTORM WIND" "ICE STORM"
## [19] "TSUNAMI" "RIP CURRENT"
## [21] "AVALANCHE" "RIP CURRENTS"
## [23] "DUST STORM" "HEAVY RAIN"
## [25] "EXTREME COLD" "STRONG WIND"
## [27] "WINTER WEATHER/MIX" "DENSE FOG"
## [29] "HIGH SURF" "LANDSLIDE"
## [31] "URBAN/SML STREAM FLD" "WIND"
## [33] "HURRICANE" "EXTREME COLD/WIND CHILL"
## [35] "BLACK ICE" "WILD/FOREST FIRE"
## [37] "HEAVY SURF/HIGH SURF" "FREEZING DRIZZLE"
## [39] "MARINE THUNDERSTORM WIND" "COLD"
## [41] "MARINE STRONG WIND" "TSTM WIND/HAIL"
## [43] "ICY ROADS" "ROUGH SEAS"
## [45] "COLD/WIND CHILL" "GLAZE"
## [47] "HAIL" "RAIN/SNOW"
## [49] "EXTREME WINDCHILL" "FROST"
## [51] "High Surf" "MARINE TSTM WIND"
## [53] "STORM SURGE" "LIGHT SNOW"
## [55] "Marine Accident" "ROUGH SURF"
## [57] "COASTAL STORM" "GUSTY WINDS"
## [59] "HEAVY SURF" "HIGH SEAS"
## [61] "LANDSLIDES" "MARINE HIGH WIND"
## [63] "MIXED PRECIP" "STRONG WINDS"
## [65] "blowing snow"
Plotting total casualty figures for each storm event.
injuries_and_fatalities %>%
filter(population_health > 10) %>%
ggplot(aes(population_health,
reorder(EVTYPE, population_health),
fill = EVTYPE)) +
geom_col(show.legend = FALSE) +
theme(axis.text = element_text(size = 5)) +
labs(x = "Injuries and fatalities", y = "Storm Event")
Storm events most harmful to population health, sorted from most harmful to least harmful
In order to calculate total damages from both crop damage and property damage, we cannot add the crop damage and property damage values because the CROPDMGEXP and PROPDMGEXP variables take values K, M and B to indicate damage in thousands of US dollars, millions of US dollars and billions of US dollars respectively. Hence the amounts need to be converted to thousands, millions and billions and then added to get the total damage value. Defined two new variables cropdmg and propdmg using case_when inside mutate converting the values to corresponding thousands, millions and billions. Selecting the EVTYPE and the two newly created variables, grouping by EVTYPE variable and calculating the total damage for each storm event by adding the cropdmg and propdmg values. Arranging the new data set obtained by total damage values in descending order, selecting the top twelve rows and plotting them against storm event type.
economic_cons <- storm_data %>%
mutate(cropdmg = case_when(
CROPDMGEXP == "K" ~ CROPDMG * 1000,
CROPDMGEXP == "M" ~ CROPDMG * 1e6,
CROPDMGEXP == "B" ~ CROPDMG * 1e9,
.default = 0),
propdmg = case_when(
PROPDMGEXP == "K" ~ PROPDMG * 1000,
PROPDMGEXP == "M" ~ PROPDMG * 1e6,
PROPDMGEXP == "B" ~ PROPDMG * 1e9,
.default = 0)
) %>%
filter(cropdmg > 0, propdmg > 0) %>%
select(EVTYPE, cropdmg, propdmg, year)
economic_cons %>%
group_by(year, EVTYPE) %>%
summarize(total_dmgs = sum(cropdmg + propdmg)) %>%
arrange(desc(total_dmgs)) %>%
head(n=25) %>%
ggplot(aes(total_dmgs/1e9, year, fill = EVTYPE)) +
geom_col(show.legend = FALSE) +
facet_wrap(~EVTYPE, scales = "free") +
labs(x = "Total damages (billion USD)", y = "Storm Event")
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
Top 10 Events that had greatest economic consequences
# Following are the events having greatest economic consequences.
economic_cons %>%
group_by(year, EVTYPE) %>%
summarize(total_dmgs = sum(cropdmg + propdmg)) %>%
arrange(desc(total_dmgs)) %>%
.$EVTYPE %>%
unique()
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
## [1] "FLOOD" "HURRICANE/TYPHOON" "HURRICANE"
## [4] "HIGH WIND" "WILDFIRE" "FLASH FLOOD"
## [7] "THUNDERSTORM WIND" "TROPICAL STORM" "HAIL"
## [10] "DROUGHT" "EXCESSIVE HEAT" "TSTM WIND"
## [13] "TORNADO" "HEAVY SNOW" "River Flooding"
## [16] "STRONG WIND" "FROST/FREEZE" "WILD/FOREST FIRE"
## [19] "TSUNAMI" "HEAVY RAIN" "ICE STORM"
## [22] "WINTER STORM" "LANDSLIDE" "TYPHOON"
## [25] "Heavy Rain/High Surf" "TSTM WIND/HAIL" "URBAN/SML STREAM FLD"
## [28] "BLIZZARD" "LIGHTNING" "EXTREME COLD"
## [31] "DUST STORM" "STORM SURGE/TIDE" "STORM SURGE"
## [34] "Frost/Freeze" "RIVER FLOOD" "FREEZE"
## [37] "SMALL HAIL" "GUSTY WINDS" "DRY MICROBURST"
We see that flood has been the single most destructive event causing greatest economic consequences, up to 120 billion USD till date.