DATA PROCESSING

Loading and preprocessing the data

library(readr)

storm <- read.csv("Reproducible Research/week2/repdata_data_StormData1.csv")
head(storm)
##   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

RESULTS

Across the United States, which typůs of events (as indicated in the EVTYPE variable) are most harmful with respect to population health? To answer this question, I’d need to identify what are the indicators of most harmful with respect to population health? Looking at the available columns in the dataset, it appears finding the large count of FATALITIES, INJURIES and directly PROPDAMAGE and CROPDAMAGE in that order, grouped by EVTYPE would help to answer this question. The top 5 are tornadoes, excessive heat, flash flood, heat, and lightning.

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
storm_health_harm <- storm %>%
  group_by(EVTYPE) %>%
  summarise(
            fatalities_total = sum(FATALITIES, na.rm = TRUE),
            injuries_total = sum(INJURIES, na.rm = TRUE)
            ) %>%
  arrange(desc(fatalities_total), desc(injuries_total)) %>%
  head(10)
## `summarise()` ungrouping output (override with `.groups` argument)

Across the United States, which types of events have the greatest economic consequences?

storm_eco_impact <- storm %>%
  group_by(EVTYPE) %>%
  summarise(
            propdmg_total = sum(PROPDMG, na.rm = TRUE),
            cropdmg_total = sum(CROPDMG, na.rm = TRUE)
            ) %>%
  arrange(desc(propdmg_total), desc(cropdmg_total)) %>%
  head(10)
## `summarise()` ungrouping output (override with `.groups` argument)

FIGURES

# Step 1: Install and load necessary packages
install.packages("ggplot2")
## Installing package into '/usr/local/lib/R/site-library'
## (as 'lib' is unspecified)
library(dplyr)
library(ggplot2)

ggplot(storm_health_harm, aes(x = reorder(EVTYPE, fatalities_total), y = fatalities_total)) +
  geom_segment(aes(xend = EVTYPE, yend = 0), color = "grey") +
  geom_point(size = 4, color = "darkred") +
  coord_flip() +
  labs(
    title = "Top 10 Storm Types by Fatalities",
    x = "Event Type",
    y = "Total Fatalities"
  ) +
  theme_minimal()

ggplot(storm_eco_impact, aes(x = reorder(EVTYPE, propdmg_total), y = propdmg_total)) +
  geom_segment(aes(xend = EVTYPE, yend = 0), color = "grey") +
  geom_point(size = 4, color = "darkred") +
  coord_flip() +
  labs(
    title = "Top 10 Storm Types by Property Damage",
    x = "Event Type",
    y = "Total Property Damage ($) in Thousands"
  ) +
  theme_minimal()