-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstock-canada-tile-grid.R
46 lines (41 loc) · 1.21 KB
/
stock-canada-tile-grid.R
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
library(tidyverse)
library(viridis)
# location df
canada <- tribble(
~province, ~code, ~x, ~y,
"Yukon", "YK", 1, 3,
"British Columbia", "BC", 1, 2,
"Northwest Territories", "NW", 2, 3,
"Alberta", "AB", 2, 2,
"Nunavut", "NU", 3, 3,
"Saskatchewan", "SK", 3, 2,
"Manitoba", "MB", 4, 2,
"Ontario", "ON", 5, 1,
"Quebec", "QC", 6, 2,
"Prince Edward Island", "PE", 7, 3,
"New Brunswick", "NB", 7, 2,
"Newfoundland and Labrador", "NL", 8, 3,
"Nova Scotia", "NS", 8, 1
)
# inspect
canada
# just make sure province = province
df <- tibble(
province = c("Ontario", "British Columbia", "Alberta", "Manitoba", "Nova Scotia"),
`Fake Data` = c(10, 4, 3, 6, 0)
)
df
# TILE GRID MAP
canada %>%
left_join(df, by = "province") %>%
ggplot(aes(x, y)) +
geom_tile(aes(fill = `Fake Data`)) +
geom_text(aes(label = code), color = "white") +
coord_fixed(ratio = 1) +
theme(
panel.background = element_blank(),
panel.grid = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank()) +
scale_fill_viridis(na.value = "#E1E1E1", option = "D", begin = 0.2, end = 0.8)