Setting Up Your Environment

# Load required libraries
# Suppress messages and warnings
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(readr)
library(knitr)

Inspect the Data: It’s important to understand the structure of your data. Use str(storm_data) to get an overview of the columns and data types, and head(storm_data) to see the first few rows of the dataset. Clean and Prepare the Data: Based on your initial inspection, decide on any necessary data transformations. This might include filtering out irrelevant columns, dealing with missing values, or transforming variables. For instance, you might need to convert the damage estimates from character to numeric format for analysis.

library(readr)
storm_data <- read_csv("/Users/esmakaylabalin/Downloads/repdata-data-StormData.csv")
## Rows: 902297 Columns: 37
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): BGN_DATE, BGN_TIME, TIME_ZONE, COUNTYNAME, STATE, EVTYPE, BGN_AZI,...
## dbl (18): STATE__, COUNTY, BGN_RANGE, COUNTY_END, END_RANGE, LENGTH, WIDTH, ...
## lgl  (1): COUNTYENDN
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Analysis Analyze Health Impact: To determine which types of events are most harmful to population health, summarize the data by event type, aggregating the total fatalities and injuries. Use dplyr functions like group_by and summarise for this purpose.

library(dplyr)
health_impact <- storm_data %>%
  group_by(EVTYPE) %>%
  summarise(Total_Fatalities = sum(FATALITIES), Total_Injuries = sum(INJURIES))

Analyze Economic Consequences: Similarly, analyze the economic impact by event type, focusing on property and crop damage.

economic_impact <- storm_data %>%
  group_by(EVTYPE) %>%
  summarise(Total_Property_Damage = sum(PROPDMG), Total_Crop_Damage = sum(CROPDMG))

Visualization: Create visualizations to represent your findings using ggplot2. For instance, a bar plot showing the top 10 events causing fatalities and injuries can be very informative.

library(ggplot2)
ggplot(health_impact, aes(x=reorder(EVTYPE, -Total_Fatalities), y=Total_Fatalities)) +
  geom_bar(stat="identity") + 
  theme(axis.text.x=element_text(angle=45, hjust=1))