library(tidyverse)
library(ggmap)
library(maps)
library(ggthemes)
library(plotly)
library(gganimate)
library(lubridate)
For my final project, I will be showing change in the number of autocratic regimes around the world over time. You can read more about the data and the motivation behind this project here
The data is created by Professor Michael K. Miller from George Washington University and hosted on his personal site.
data <- read.table("https://raw.githubusercontent.com/saayedalam/Data/master/AutocraticRulingPartiesDataset_cy.txt")
The dataset requires some data cleaning as it has several variables that will not used. Moreover, the data has to be transformed in order to extract geolocation. I will get in to more details on my final project.
dt <- data %>%
filter(Party_Regime == 1) %>%
select(Country, Year) %>%
add_count(Year, name = "Party_Per_Year") %>%
mutate(Year = as.factor(Year))
longlat <- dt %>%
distinct(Country) %>%
mutate(Country = as.character(Country)) %>%
mutate_geocode(Country)
dt <- longlat %>%
right_join(dt)
## Warning: Column `Country` joining character vector and factor, coercing into
## character vector
head(dt)
## # A tibble: 6 x 5
## Country lon lat Year Party_Per_Year
## <chr> <dbl> <dbl> <fct> <int>
## 1 Afghanistan 67.7 33.9 1974 64
## 2 Afghanistan 67.7 33.9 1975 70
## 3 Afghanistan 67.7 33.9 1976 72
## 4 Afghanistan 67.7 33.9 1977 73
## 5 Afghanistan 67.7 33.9 1978 75
## 6 Afghanistan 67.7 33.9 1979 75
Next, I create a layer of map using ggplot and then map the number of autocratic regimes around the world.
world <- ggplot() +
borders("world", colour = "gray85", fill = "gray80") +
theme_map()
world
map <- world +
geom_point(aes(x = lon, y = lat, size = Party_Per_Year),
data = dt, colour = 'red', alpha = 0.3) +
scale_size(range = c(1, 7), breaks = c(1, 16, 31, 46, 61, 76)) +
theme(legend.position = 'right') +
labs(size = "Parties")
map
In the final project, I will animate the above graph to show change in numbers of party over time. It will show from which parts of the world autocratic regimes started, which continents were affected the most, the period when the world saw the most regimes and finally, how the number started to drop by the end of 2015.