-
Notifications
You must be signed in to change notification settings - Fork 0
/
2021_03_23_tidy_tuesday.Rmd
143 lines (97 loc) · 2.8 KB
/
2021_03_23_tidy_tuesday.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
---
title: "TidyTemplate"
date: 2021-03-25
output: html_output
---
[David Robinson](https://www.youtube.com/watch?v=WxKSauhOY4g&list=PL19ev-r1GBwkuyiwnxoHTRC8TTqP8OEi8&index=1) on his screencasts at first.
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(tidytuesdayR)
library(scales)
theme_set(theme_light())
```
# Load the weekly Data
Download the weekly data and make available in the `tt` object.
```{r Load}
tt <- tt_load("2021-03-23")
```
```{r mutate}
unvotes <- tt$unvotes %>%
mutate(vote_number = match(vote, c("no","abstain","yes")) -2) %>%
left_join(tt$roll_calls %>%
select(rcid, date, amend), by = "rcid")
unvotes %>%
count(country, sort = TRUE)
```
```{r votes}
summarise_votes <- function(tbl, min_votes = 10) {
tbl %>%
summarise(n_votes =n(),
n_yes = sum(vote == "yes"),
pct_yes = n_yes / n_votes) %>%
filter(n_votes >= min_votes) %>%
arrange(desc(pct_yes))
}
by_country <- unvotes %>%
group_by(country) %>%
summarise_votes()
by_country %>%
slice(c(1:10, (n() - 10):n())) %>%
mutate(country = fct_reorder(country, pct_yes)) %>%
ggplot(aes(pct_yes, country)) +
geom_point(aes(size = n_votes)) +
scale_x_continuous(labels = percent) +
labs(x = "% of yes votes in UN",
title = "What countries voted yes the least")
```
```{r}
library(lubridate)
unvote
by_year <- unvotes %>%
group_by(year = year(date)) %>%
summarise_votes()
by_year %>%
ggplot(aes(year, pct_yes))+
geom_line()+
expand_limits(y = 0)
by_country_year <- unvotes %>%
group_by(year = year(date),
country) %>%
summarise_votes()
by_country_year %>%
filter(country %in% c("United States", "Canada", "Mali", "Israel")) %>%
mutate(country = fct_reorder(country, pct_yes)) %>%
ggplot(aes(year, pct_yes, colour = country))+
geom_line()+
scale_color_discrete(guide = guide_legend(reverse = TRUE))+
expand_limits(y = 0)
```
# Readme
Take a look at the readme for the weekly data to get insight on the dataset.
This includes a data dictionary, source, and a link to an article on the data.
```{r Readme, eval = interactive()}
tt
```
# Glimpse Data
Take an initial look at the format of the data available.
```{r Glimpse}
tt %>%
map(glimpse)
```
# Wrangle
Explore the data and process it into a nice format for plotting! Access each dataset by name by using a dollarsign after the `tt` object and then the name of the data set.
```{r Wrangle}
```
# Visualize
Using your processed dataset, create your unique visualization.
```{r Visualize}
```
# Save Image
Save your image for sharing. Be sure to use the `#TidyTuesday` hashtag in your post on twitter!
```{r}
# This will save your most recent plot
ggsave(
filename = "My TidyTuesday Plot.png",
device = "png")
```