Let’s take a look at the voting history of countries in the United Nations General Assembly. We will be using data from the unvotes package. Additionally, we will make use of the tidyverse and lubridate packages for the analysis, and the DT package for interactive display of tabular output.
library(tidyverse)
library(unvotes)
library(lubridate)
library(DT)
The unvotes package provides three datasets we can work with: un_roll_calls
, un_roll_call_issues
, and un_votes
. Each of these datasets contains a variable called rcid
, the roll call id, which can be used as a unique identifier to join them with each other.
un_votes
dataset provides information on the voting history of the United Nations General Assembly. It contains one row for each country-vote pair.un_roll_calls
dataset contains information on each roll call vote of the United Nations General Assembly.un_roll_call_issues
dataset contains (topic) classifications of roll call votes of the United Nations General Assembly. Many votes had no topic, and some have more than one.Let’s create a visualization that we create a visualization that displays how the voting record of the United States changed over time on a variety of issues, and compares it to another country. The other country we’ll display is Turkey.
un_votes %>%
filter(country %in% c("United States of America", "Turkey", "Ireland")) %>%
inner_join(un_roll_calls, by = "rcid") %>%
inner_join(un_roll_call_issues, by = "rcid") %>%
mutate(issue = ifelse(issue == "Nuclear weapons and nuclear material",
"Nuclear weapons and materials", issue)) %>%
group_by(country, year = year(date), issue) %>%
summarize(
votes = n(),
perc_yes = mean(vote == "yes")
) %>%
filter(votes > 5) %>% # only use records where there are more than 5 votes
ggplot(mapping = aes(x = year, y = perc_yes, color = country)) +
geom_point() +
geom_smooth(method = "loess", se = FALSE) +
facet_wrap(~ issue) +
labs(
title = "Percentage of Yes votes in the UN General Assembly",
subtitle = "1946 to 2015",
y = "% Yes",
x = "Year",
color = "Country"
)
We can easily change which countries are being plotted by changing which countries the code above filter
s for. Note that the country name should be spelled and capitalized exactly the same way as it appears in the data. See the Appendix for a list of the countries in the data.
Below is a list of countries in the dataset: