Initially the data will be loaded into noaa_data with the read.csv function. Next, to answer the questions posed, the most frequent events related to deaths are studied, totaling the number of deaths according to the type of event. This same analysis is later done for the injuries. In both cases a graph is shown to facilitate understanding of the results.
To determine which events have the greatest economic consequences, the variables that report damage to crops and utensils are totaled and the results are shown by type of event.
The data is loaded and named as noaa_data
# Loading required libraries
library(readr)
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)
## Warning: package 'ggplot2' was built under R version 4.4.1
#Loading the data
noaa_data <- read.csv("repdata_data_StormData.csv.bz2", header = TRUE)
Question 1: Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health? ———————————————————————————–
In the graph you can see the 10 events that cause the most deaths:
#Create a variable with the sum of deaths according to the type of event
fatalities_evt <- noaa_data %>%
group_by(EVTYPE) %>%
summarise(Total_Fatalities = sum(FATALITIES)) %>%
arrange(desc(Total_Fatalities))
#Shows an ordered list of the ten most frequent events
ggplot(head(fatalities_evt, 10), aes(x = reorder(EVTYPE, Total_Fatalities), y = Total_Fatalities)) +
geom_bar(stat = "identity", fill = "green") +
coord_flip() +
labs(title = "Top 10 fatality causing events",
x = "Event type",
y = "Total fatalities")
In the graph you can see the 10 events that cause the most injures:
#Create a variable with the sum of injuries according to the type of event
injuries_evt <- noaa_data %>%
group_by(EVTYPE) %>%
summarise(Total_Injuries = sum(INJURIES)) %>%
arrange(desc(Total_Injuries))
#Shows an ordered list of the ten most frequent events
ggplot(head(injuries_evt, 10), aes(x = reorder(EVTYPE, Total_Injuries), y = Total_Injuries)) +
geom_bar(stat = "identity", fill = "blue") +
coord_flip() +
labs(title = "Top 10 injures causing events",
x = "Event type",
y = "Total tnjures")
In the graph you can see the 10 events that cause the most economic damage:
#Create a variable with the sum of damage according to the type of event
economic_cons <- noaa_data %>%
group_by(EVTYPE) %>%
summarise(T_Prop_Dmg = sum(PROPDMG),
T_Crop_Dmg = sum(CROPDMG)) %>%
mutate(T_economic_cons = T_Prop_Dmg + T_Crop_Dmg) %>%
arrange(desc(T_economic_cons))
##Shows an ordered list of the ten most frequent events
ggplot(head(economic_cons, 10), aes(x = reorder(EVTYPE, T_economic_cons), y = T_economic_cons)) +
geom_bar(stat = "identity", fill = "red") +
coord_flip() +
labs(title = "Top 10 weather events with greatest economic consequences",
x = "Event type",
y = "Total economic")
According to these results, the United States government should pay special attention to the most damaging events, such as the tornado, excessive heat, flash flood, flood and TSTM wind.