Graph linear model plots with sjPlots in R

This blog post will look at the plot_model() function from the sjPlot package. This plot can help simply visualise the coefficients in a model. Packages we need: We can look at variables that are related to citizens’ access to public services. This dependent variable measures equal access access to basic public services, such as access to security, primary education, clean water, and healthcare and whether … 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 will be the end of their term, when they get … 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, so I can use this variable to filter away all … 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 with a transparent background. The pie chart will show which … 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 serves to highlight trends. Blue means the country enjoys high … 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 most recent round of the ESS survey, conducted in 2018. … 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 the Wikipedia, a self-coup, or autocoup (from the Spanish autogolpe), is a form of … 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, rather than coerce or bribe other countries to view your … 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 survey package was created by Thomas Lumley, a professor from … 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 ends. It turns out that 1994 was a very coup-prone … Continue reading Analyse Pseudo-R2, VIF scores and robust standard errors for generalised linear models in R