Synopsis: This analysis examines the NOAA Storm Database to identify which weather events are most harmful to population health and have the greatest economic consequences in the United States. Using data from 1950 to 2011, we process the raw data to analyze fatalities, injuries, and economic damage. The results show that [brief summary of findings]

Data Processing

Loading the Data

storm_data <- read.csv("repdata_data_StormData.csv.bz2")  # Replace with actual filename

##Data Cleaning and Processing

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)

# Standardize event types
storm_data$EVTYPE <- toupper(trimws(storm_data$EVTYPE))

# Calculate total health impact
storm_data <- storm_data %>%
  mutate(TOTAL_HEALTH = FATALITIES + INJURIES)

# Calculate economic impact (adjust units)
storm_data <- storm_data %>%
  mutate(
    PROPDMG_ADJ = PROPDMG * case_when(
      PROPDMGEXP %in% c("K", "k") ~ 1000,
      PROPDMGEXP %in% c("M", "m") ~ 1000000,
      PROPDMGEXP %in% c("B", "b") ~ 1000000000,
      TRUE ~ 1
    ),
    CROPDMG_ADJ = CROPDMG * case_when(
      CROPDMGEXP %in% c("K", "k") ~ 1000,
      CROPDMGEXP %in% c("M", "m") ~ 1000000,
      CROPDMGEXP %in% c("B", "b") ~ 1000000000,
      TRUE ~ 1
    ),
    TOTAL_ECONOMIC = PROPDMG_ADJ + CROPDMG_ADJ
  )

##Most Harmfull events for population Health

top_health <- storm_data %>%
  group_by(EVTYPE) %>%
  summarise(TOTAL_HEALTH = sum(TOTAL_HEALTH)) %>%
  arrange(desc(TOTAL_HEALTH)) %>%
  head(10)

ggplot(top_health, aes(x = reorder(EVTYPE, -TOTAL_HEALTH), y = TOTAL_HEALTH)) +
  geom_bar(stat = "identity", fill = "steelblue") +
  labs(title = "Top 10 Most Harmful Weather Events to Population Health",
       x = "Event Type",
       y = "Total Impact (Fatalities + Injuries)") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

##TONADO HAS BEEN THE MOST HARMFULL FOR HUMAN HEALTH

##Events with Greatest Economic Consequences

top_economic <- storm_data %>%
  group_by(EVTYPE) %>%
  summarise(TOTAL_ECONOMIC = sum(TOTAL_ECONOMIC)/1000000) %>% # Convert to millions
  arrange(desc(TOTAL_ECONOMIC)) %>%
  head(10)

ggplot(top_economic, aes(x = reorder(EVTYPE, -TOTAL_ECONOMIC), y = TOTAL_ECONOMIC)) +
  geom_bar(stat = "identity", fill = "darkred") +
  labs(title = "Top 10 Weather Events with Greatest Economic Consequences",
       x = "Event Type",
       y = "Total Damage (in Millions USD)") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

##FLOOD IS THE MOST EXPENSIVE ECONOMIC CONSEQUENCES