Last active
May 30, 2017 14:47
-
-
Save svmiller/cdf3413e2874e67bf77386603225c247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setwd("~/Dropbox/projects/blog-posts/nato-spending") | |
library(WDI) | |
library(countrycode) | |
library(tidyverse) | |
Milit <- WDI(country="all", indicator=c("MS.MIL.XPND.GD.ZS", "MS.MIL.XPND.ZS","MS.MIL.TOTL.P1", "SP.POP.TOTL"), | |
start=1988, end=2015) %>% | |
rename(milex = MS.MIL.XPND.GD.ZS, milgovexp = MS.MIL.XPND.ZS, | |
milper = MS.MIL.TOTL.P1, tpop = SP.POP.TOTL) %>% tbl_df() %>% | |
mutate(ccode = countrycode(iso2c, "iso2c", "cown"), | |
ccode = ifelse(iso2c == "RS", 345, ccode), | |
militarization = milper/tpop) %>% | |
select(-iso2c) %>% | |
arrange(ccode,year) | |
Milit %>% | |
filter(ccode == 2 | ccode == 20 | ccode == 200 | (ccode >= 210 & ccode <= 220) | | |
ccode == 230 | ccode == 235 | ccode == 255 | (ccode == 290 & year >= 1999) | | |
(ccode == 310 & year >= 1999) | (ccode == 316 & year >= 1999) | | |
(ccode == 317 & year >= 2004) | ccode == 325 | (ccode == 339 & year >= 2009) | | |
(ccode == 344 & year >= 2009) | (ccode == 349 & year >= 2004) | | |
ccode == 350 | (ccode == 355 & year >= 2004) | (ccode == 360 & year >= 2004) | | |
(ccode == 366 & year >= 2004) | (ccode == 367 & year >= 2004) | | |
(ccode == 368 & year >= 2004) | (ccode >= 385 & ccode < 400) | | |
ccode == 640) -> NATO | |
theme_steve <- function() { | |
theme_bw() + | |
theme(panel.border = element_blank(), | |
plot.caption=element_text(hjust=1, size=9, | |
margin=margin(t=10), | |
face="italic"), | |
plot.title=element_text(hjust=0, size=18, | |
margin=margin(b=10), | |
face="bold"), | |
axis.title.y=element_text(size=12,hjust=1, | |
face="italic"), | |
axis.title.x=element_text(hjust=1, size=12, face="italic")) | |
} | |
NATO %>% | |
filter(milex >= 2) -> meets2 | |
Milit %>% filter(year == 2015) %>% summarize(med = median(milgovexp, na.rm=T)) -> medmilgovexp2015 | |
ggplot(NATO, aes(year, milex)) + facet_wrap( ~ country, ncol=4) + | |
geom_line() + geom_hline(yintercept = 2, linetype = "dashed") + | |
scale_x_continuous(breaks=seq(1990, 2015, by=5)) + theme_steve() + | |
xlab("") + ylab("") + ggtitle("NATO Military Expenditures as % of GDP, 1988-2015") + | |
geom_ribbon(data=meets2, aes(x=year,ymax=milex),ymin=0, ymax=6, fill="red", alpha=0.3) + | |
labs(caption="Military expenditure data come from SIPRI. Estonia and Poland approximate 2% though geom_ribbon in ggplot2 wants to connect the entire stretch. I'm working on it. Please don't yell at me. :-(") | |
ggsave(file="nato-milex-spending.png", width=13.33, height=9.77) | |
ggplot(NATO, aes(year, milgovexp)) + facet_wrap( ~ country, ncol=4) + | |
geom_line() + geom_hline(yintercept = as.numeric(medmilgovexp2015[1,1]), linetype = "dashed") + | |
scale_x_continuous(breaks=seq(1990, 2015, by=5)) + theme_steve() + | |
xlab("") + ylab("") + ggtitle("NATO Military Expenditures as % of Central Government Expenditures, 1988-2015") + | |
# geom_ribbon(data=meets2, aes(x=year,ymax=milex),ymin=0, ymax=6, fill="red", alpha=0.3) + | |
labs(caption="Military expenditure data come from SIPRI. Dashed line communicates global median of military goverment expenditures for 2015.") | |
ggsave(file="nato-milex-gov-spending.png", width=13.33, height=9.77) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment