# Update the path to where your file is located if needed
storm_data <- read.csv(bzfile("C:/Users/User/Downloads/repdata_data_StormData.csv.bz2"))
# Summarize fatalities and injuries by event type
health_impact <- storm_data %>%
group_by(EVTYPE) %>%
summarise(
fatalities = sum(FATALITIES, na.rm = TRUE),
injuries = sum(INJURIES, na.rm = TRUE),
total = fatalities + injuries
) %>%
arrange(desc(total))
# Show top 10
head(health_impact, 10)
## # A tibble: 10 × 4
## EVTYPE fatalities injuries total
## <chr> <dbl> <dbl> <dbl>
## 1 TORNADO 5633 91346 96979
## 2 EXCESSIVE HEAT 1903 6525 8428
## 3 TSTM WIND 504 6957 7461
## 4 FLOOD 470 6789 7259
## 5 LIGHTNING 816 5230 6046
## 6 HEAT 937 2100 3037
## 7 FLASH FLOOD 978 1777 2755
## 8 ICE STORM 89 1975 2064
## 9 THUNDERSTORM WIND 133 1488 1621
## 10 WINTER STORM 206 1321 1527
# Plot the top 10 events impacting health
top_health <- head(health_impact, 10)
ggplot(top_health, aes(x = reorder(EVTYPE, total), y = total)) +
geom_bar(stat = "identity", fill = "tomato") +
coord_flip() +
labs(
title = "Top 10 Events Harmful to Population Health",
x = "Event Type",
y = "Total Injuries + Fatalities"
)
# Plot the top 10 events by fatalities
top_fatalities <- health_impact %>% arrange(desc(fatalities)) %>% head(10)
ggplot(top_fatalities, aes(x = reorder(EVTYPE, fatalities), y = fatalities)) +
geom_bar(stat = "identity", fill = "darkred") +
coord_flip() +
labs(
title = "Top 10 Events by Fatalities",
x = "Event Type",
y = "Number of Fatalities"
)
economic_impact <- storm_data %>%
group_by(EVTYPE) %>%
summarise(
property = sum(PROPDMG, na.rm = TRUE),
crop = sum(CROPDMG, na.rm = TRUE),
total = property + crop
) %>%
arrange(desc(total))
head(economic_impact, 10)
## # A tibble: 10 × 4
## EVTYPE property crop total
## <chr> <dbl> <dbl> <dbl>
## 1 TORNADO 3212258. 100019. 3312277.
## 2 FLASH FLOOD 1420125. 179200. 1599325.
## 3 TSTM WIND 1335966. 109203. 1445168.
## 4 HAIL 688693. 579596. 1268290.
## 5 FLOOD 899938. 168038. 1067976.
## 6 THUNDERSTORM WIND 876844. 66791. 943636.
## 7 LIGHTNING 603352. 3581. 606932.
## 8 THUNDERSTORM WINDS 446293. 18685. 464978.
## 9 HIGH WIND 324732. 17283. 342015.
## 10 WINTER STORM 132721. 1979. 134700.
# Plot the top 10 events with greatest economic impact
top_economic <- head(economic_impact, 10)
ggplot(top_economic, aes(x = reorder(EVTYPE, total), y = total)) +
geom_bar(stat = "identity", fill = "steelblue") +
coord_flip() +
labs(
title = "Top 10 Events with Greatest Economic Impact",
x = "Event Type",
y = "Total Property + Crop Damage"
)
You can refine this analysis by normalizing values or cleaning the
EVTYPE names further.