Visualizing Natural Disaster Cost

Visualizing Natural Disaster Cost

This is my note for learning Visualizing Natural Disaster Cost.

If you cannot download data-2.tsv from the provided URL, you can download it from data-2.tsv.

R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
library(rvest)
library(ggplot2)
library(dplyr)
library(awtools)
library(ggbeeswarm)
library(ggforce)
download.file('https://static01.nyt.com/newsgraphics/2017/08/29/expensive-storms/79088630ae1af934d7840e104a0e3f1e8a6c7bf1/data-2.tsv', 'data-2.tsv')
disasters <- read.csv('data-2.tsv',
sep='\t',
stringsAsFactors = FALSE)
costs <- disasters %>%
mutate(
Disaster = case_when(
col2 == '#397dc2' ~ 'Hurricane',
col2 == '#efba2b' | col2 == '#9b0e11' ~ 'Drought/Fire',
col2 == '#699d8f' ~ 'Flooding',
col2 == '#9d76b0' ~ 'Storm',
col2 == '#61c6e2' ~ 'Winter Storm'
)
)
R
1
2
3
4
5
6
7
8
9
10
11
ggplot(costs, aes(x = year, y = Disaster, color = Disaster)) + 
geom_quasirandom(
alpha = 0.75,
aes(size = cost),
groupOnX = FALSE,
show.legend = FALSE) +
a_primary_color() +
labs(title = "Billion Dollar Natural Disasters",
subtitle = "The most costly natural disasters from 1980 - 2017",
y = '',
caption = 'Data: New York Times\nOriginal Article: "The Cost of Hurricane Harvey: Only One Recent Storm Comes Close')

R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
total.cost <- costs %>% 
group_by(Disaster) %>%
arrange(Disaster, year) %>%
mutate(total = cumsum(cost))

ggplot(total.cost,
aes(x = year,
y = total,
fill = Disaster,
group = Disaster)) +
geom_line(size = 0.5, aes(color = Disaster)) +
geom_point(aes(color = Disaster)) +
a_primary_color() +
a_primary_fill() +
labs(title = 'Natural Disasters and Runaway Cost',
subtitle = 'Running total of cost of natural disasters \n(over $1 billion in estimated cost) from 1980 - 2017',
caption = 'Data: New York Times')

# R

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×