-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2021-03-23-TidyTuesday_UN.R
75 lines (62 loc) · 2.36 KB
/
2021-03-23-TidyTuesday_UN.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
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
##### TidyTuesday 2021-03-23 #####
### UN votes ###
### Author: Patrizia Maier ###
# get packages
library(tidyverse)
library(rnaturalearth)
library(tmap)
library(gifski)
library(extrafont)
# font_import() # only once
loadfonts(device = "win", quiet = TRUE) # every time
# get tidy tuesday data
tuesdata <- tidytuesdayR::tt_load('2021-03-23')
unvotes <- tuesdata$unvotes
roll_calls <- tuesdata$roll_calls
issues <- tuesdata$issues
# get map data
world <- ne_countries(returnclass='sf') %>%
select("iso_a2", "geometry")
# combine data
temp <- unvotes %>%
left_join(roll_calls, by="rcid") %>%
left_join(issues, by="rcid") %>%
filter(importantvote==1)
data <- world %>% left_join(temp %>%
filter(issue=="Nuclear weapons and nuclear material") %>%
group_by(date),
by=c("iso_a2"="country_code")) %>%
drop_na(date) %>%
arrange(date) %>%
mutate(vote=factor(vote, levels=c("yes", "abstain", "no")))
# create map
tmap_style("beaver")
animation <- tm_shape(data) +
tm_fill(col="vote", legend.show=TRUE, palette="-RdYlGn") +
tm_facets(by="date", free.coords=FALSE, drop.units=TRUE, drop.NA.facets=TRUE, nrow = 1, ncol = 1) +
tm_layout(frame=F,
main.title="UN Votes \non Important Issues of Nuclear Weapons and Material",
main.title.position="left",
main.title.size=2,
main.title.color="black",
legend.position=c("left", "bottom"),
legend.title.size=1.5,
legend.text.size=1.25,
panel.label.size=1.5,
panel.label.bg.color="#5b92e5",
panel.label.color="white",
fontfamily="Bahnschrift") +
tm_shape(data) +
tm_borders(col="black") +
tm_logo("https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/UN_emblem_blue.svg/1000px-UN_emblem_blue.svg.png",
position=c("center", "bottom"),
height=4)+
tm_credits("by @PatriziaMaier for #TidyTuesday \nData: Harvard's Dataverse",
position=c("right", "bottom"),
size=0.8,
bg.color="#5b92e5",
bg.alpha=0.95,
col="white")
# save as gif
tmap_animation(animation, filename="C:/Users/Patrizia/Data/Data Science/TidyTuesday/un_votes.gif", delay=150, restart.delay=500,
width=1200, height=600)