## Graph linear model plots with sjPlots in R

This blog post will look at the plot_model() function from the sjPlot package which can help visualise the coefficients in a model in a plot. Packages we need: We can look at variables that are related to the extent to which citizens’ access to state public services is equally distributed across socio-economic groups. The variable … Continue reading Graph linear model plots with sjPlots in R

## Make a timeline graph with dates in ggplot2

We will use the geom_segment layer from ggplot2 to make a timeline graph! This layer takes both x and y as well as xend and yend inputs for the start and end of the segment lines in the plot. For our timeline, the x will be the start of each Irish Taoiseach’s term. The xend … Continue reading Make a timeline graph with dates in ggplot2

## Examining speeches from the UN Security Council Part 1

Let’s look at how many speeches took place at the UN Security Council every year from 1995 until 2019. I want to only look at countries, not organisations. So a quick way to do that is to add a variable to indicate whether the speaker variable has an ISO code. Only countries have ISO codes, … Continue reading Examining speeches from the UN Security Council Part 1

## Improve your visualizations with ggsave in R

When we save our plots and graphs in R, we can use the ggsave() function and specify the type, size and look of the file. We are going to look two features in particular: anti-aliasing lines with the Cairo package and creating transparent backgrounds. Make your graph background transparent First, let’s create a pie chart … Continue reading Improve your visualizations with ggsave in R

## Create a correlation matrix with GGally package in R

We can create very informative correlation matrix graphs with one function. Packages we will need: First, choose some nice hex colors. Next, we can go create a dichotomous factor variable and divide the continuous “freedom from torture scale” variable into either above the median or below the median score. It’s a crude measurement but it … Continue reading Create a correlation matrix with GGally package in R

## Add weights to survey data with survey package in R: Part 2

Click here to read why need to add pspwght and pweight to the ESS data in Part 1. Packages we will need: Click here to learn how to access and download ESS round data for the thirty-ish European countries (depending on the year). So with the essurvey package, I have downloaded and cleaned up the … Continue reading Add weights to survey data with survey package in R: Part 2

## Add circular flags to maps and graphs with ggflags package in R

Packages we will need: Click here to add rectangular flags to graphs and click here to add rectangular flags to MAPS! Apropos of this week’s US news, we are going to graph the number of different or autocoups in South America and display that as both maps and bar charts. According to our pals at … Continue reading Add circular flags to maps and graphs with ggflags package in R

## BBC style graphs with bbplot package in R

Packages we will need: Click here to check out the vignette to read about all the different graphs with which you can use bbplot ! We will look at the Soft Power rankings from Portland Communications. According to Wikipedia, In politics (and particularly in international politics), soft power is the ability to attract and co-opt, … Continue reading BBC style graphs with bbplot package in R

## Add weights to survey data with survey package in R: Part 1

With the European Social Survey (ESS), we will examine the different variables that are related to levels of trust in politicians across Europe in the latest round 9 (conducted in 2018). Click here for Part 2. Click here to learn about downloading ESS data into R with the essurvey package. Packages we will need: The … Continue reading Add weights to survey data with survey package in R: Part 1

## Analyse Pseudo-R2, VIF scores and robust standard errors for generalised linear models in R

This blog post will introduce a simple function from the jtools package that can give us two different pseudo R2 scores, VIF score and robust standard errors for our GLM models in R Packages we need: From the Varieties of Democracy dataset, we can examine the v2regendtype variable, which codes how a country’s governing regime … Continue reading Analyse Pseudo-R2, VIF scores and robust standard errors for generalised linear models in R

## Add rectangular flags to maps in R

We will make a graph to map the different colonial histories of countries in South-East Asia! Click here to add circular flags. Packages we will need: I use the COLDAT Colonial Dates Dataset by Bastien Becker (2020). We will only need the first nine columns in the dataset: Next we will need to turn the … Continue reading Add rectangular flags to maps in R

## Graph countries on the political left right spectrum

In this post, we can compare countries on the left – right political spectrum and graph the trends. In the European Social Survey, they ask respondents to indicate where they place themselves on the political spectrum with this question: “In politics people sometimes talk of ‘left’ and ‘right’. Where would you place yourself on this … Continue reading Graph countries on the political left right spectrum

## Download European Social Survey data with essurvey package in R

The European Social Survey (ESS) measure attitudes in thirty-ish countries (depending on the year) across the European continent. It has been conducted every two years since 2001. The survey consists of a core module and two or more ‘rotating’ modules, on social and public trust; political interest and participation; socio-political orientations; media use; moral, political and … Continue reading Download European Social Survey data with essurvey package in R

## Add rectangular flags to graphs with ggimage package in R

This quick function can add rectangular flags to graphs. Click here to add circular flags with the ggflags package. The data comes from a Wikipedia table on a recent report by OECD’s Overseas Development Aid (ODA) from donor countries in 2019. Click here to read about scraping tables from Wikipedia with the rvest package in … Continue reading Add rectangular flags to graphs with ggimage package in R

## Scrape NATO defense expenditure data from Wikipedia with the rvest package in R

We can all agree that Wikipedia is often our go-to site when we want to get information quick. When we’re doing IR or Poli Sci reesarch, Wikipedia will most likely have the most up-to-date data compared to other databases on the web that can quickly become out of date. So in R, we can scrape … Continue reading Scrape NATO defense expenditure data from Wikipedia with the rvest package in R

## Download WorldBank data with WDI package in R

Use this package to really quickly access all the indicators from the World Bank website. With the WDIsearch() function we can look for the World Bank indicator that measures oil rents as a percentage of a country’s GDP. You can look at the World Bank website and browse all the indicators available. The output is: … Continue reading Download WorldBank data with WDI package in R

## Interpret multicollinearity tests from the mctest package in R

Packages we will need : The mctest package’s functions have many multicollinearity diagnostic tests for overall and individual multicollinearity. Additionally, the package can show which regressors may be the reason of for the collinearity problem in your model. Click here to read the CRAN PDF for all the function arguments available. So – as always … Continue reading Interpret multicollinearity tests from the mctest package in R

## Check linear regression assumptions with gvlma package in R

Packages we will need: gvlma stands for Global Validation of Linear Models Assumptions. See Peña and Slate’s (2006) paper on the package if you want to check out the math! Linear regression analysis rests on many MANY assumptions. If we ignore them, and these assumptions are not met, we will not be able to trust … Continue reading Check linear regression assumptions with gvlma package in R

## Download economic and financial time series data with Quandl package in R

Packages we will need: The website Quandl.com is a great resource I came across a while ago, where you can download heaps of datasets for variables such as energy prices, stock prices, World Bank indicators, OECD data other random data. In order to download the data from the site, you need to first set up … Continue reading Download economic and financial time series data with Quandl package in R

## Visualise panel data regression with ExPanDaR package in R

The ExPand package is an example of a shiny app. What is a shiny app, you ask? Click to look at a quick Youtube explainer. It’s basically a handy GUI for R. When we feed a panel data.frame into the ExPanD() function, a new screen pops up from R IDE (in my case, RStudio) and … Continue reading Visualise panel data regression with ExPanDaR package in R