-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
us-post-offices.Rmd
94 lines (79 loc) · 3.25 KB
/
us-post-offices.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
title: "Post offices in the USA from 1772 to 2000"
description: |
Graphs and analysis using the #TidyTuesday data set for week 16 of 2021
(13/4/2021): "US post offices"
author:
- name: Ronan Harrington
url: https://github.com/rnnh/
date: 04-16-2021
repository_url: https://github.com/rnnh/TidyTuesday/
preview: us-post-offices_files/figure-html5/figure2-1.png
output:
distill::distill_article:
self_contained: false
toc: true
---
## Setup
Loading the `R` libraries, [data set](https://github.com/rfordatascience/tidytuesday/blob/master/data/2021/2021-04-13/readme.md),
and a [shapefile for the USA](https://hub.arcgis.com/datasets/1b02c87f62d24508970dc1a6df80c98e_0?geometry=112.602%2C27.335%2C17.328%2C66.497).
```{r setup, code_folding=TRUE, include=TRUE}
# Loading libraries
library(tidyverse)
library(tidytuesdayR)
library(gganimate)
library(sf)
# Loading data set
tt <- tt_load("2021-04-13")
# Loading USA shapefile
usa_shapefile <- read_sf("~/TidyTuesday/data/States_shapefile-shp/")
```
Wrangling data for visualisation.
```{r, code_folding=TRUE, include=TRUE}
# Creating a filtered, tidy tibble with one row per post office with coordinates
post_office_est <- tt$post_offices %>%
filter(coordinates == TRUE) %>%
filter(!is.na(established)) %>%
filter(established >= 1772 & established <= 2021) %>%
filter(longitude <= 100) %>%
filter(!is.na(stamp_index) & stamp_index <= 9) %>%
select(established, latitude, longitude, stamp_index)
post_office_est$established <- post_office_est$established %>% as.integer()
```
## Plotting US post offices from 1772 to 2000
In this section, post offices in the USA are plotted in the order they were
established. This animation begins in the 1772 and ends in 2000. Each point
represents one post office, with the colour of each point corresponding to the
scarcity of postmarks from that post office. The lighter the point, the rarer
the postmark. The order in which post offices are established follows the
colonisation of America, with post offices first appearing on the east coast
before moving west.
```{r figure1, code_folding=TRUE, include=TRUE}
# Creating an animation with one point per post office from 1772 to 2000
p <- ggplot(usa_shapefile) +
geom_sf() +
geom_point(aes(longitude, latitude, colour = stamp_index),
data = post_office_est) +
scale_fill_continuous(type = "gradient") +
transition_time(established, range = c(1772L, 2000L)) +
ease_aes("linear") +
theme_void() +
theme(legend.position = "none") +
labs(title = "Post offices established each year in the US",
subtitle = "Lighter points indicate rarer postmarks. Year: {frame_time}")
# Rendering the animation as a .gif
animate(p, nframes = 400, fps = 5, renderer = magick_renderer())
```
Here are all these post offices in one static plot.
```{r figure2, code_folding=TRUE, include=TRUE, fig.height=5, fig.width=6}
# All the post offices on the USA shapefile in a static plot
ggplot(usa_shapefile) +
geom_sf() +
geom_point(aes(longitude, latitude, colour = stamp_index),
data = post_office_est) +
scale_fill_continuous(type = "gradient") +
theme_void() +
theme(legend.position = "none") +
labs(title = "Post offices in the US",
subtitle = "Lighter points indicate rarer postmarks")
```