Government positions from party-level Manifesto data (with R)

In empirical research in political science and public policy, we often need estimates of the political positions of governments (cabinets) and the salience of different issues for different governments (cabinets). Data on policy positions and issue salience is available, but typically at the level of political parties. One prominent source of data for issue salience and positions is the Manifesto Corpus, a database of the electoral manifestos of political parties. To ease the aggregation of government positions and salience from party-level Manifesto data, I developed a set of functions in R that accomplish just that, combining the Manifesto data with data on the duration and composition of governments from ParlGov.

The see how the functions work, read this detailed tutorial.

You can access all the functions at the dedicated GitHub repository. And you can contribute to this project by forking the code on GitHub. If you have questions or suggestions, get in touch.


Visualizing left-right government positions

How does the political landscape of Europe change over time? One way to approach this question is to map the socio-economic left-right positions of the governments in power. So let’s plot the changing ideological  positions of the governments using data from the Manifesto project! As you will see below, this proved to be a more challenging task than I imagined, but the preliminary results are worth sharing nonetheless.

First, we need to extract the left-right positions from the Manifesto dataset. Using the function described here, this is straightforward:

lr2000<-manifesto.position('rile', start=2000, end=2000)

This compiles the (weighted) cabinet positions for the European countries for the year 2000. Next, let’s generate a static map. We can use the new package rworldmap for this purpose. Let’s also build a custom palette that maps colors to left-right values. Since in Europe red traditionally is the color of the political left (the socialists), the palette ranges from dark red to gray to dark blue (for the right-wing governments).

library (rworldmap)
op <- palette(c('red4','red3','red2','red1','grey','blue1', 'blue2','blue3', 'blue4'))

After recoding the name of the UK, we are ready to bind our data and plot the map. You can save the map as a png file.

lr2000$State<-recode(lr$State, "'Great Britain'='United Kingdom'")

lrmapdata <- joinCountryData2Map( lr2000,joinCode = "NAME", nameJoinColumn = "State", mapResolution='medium')

png(file='LR2000map.png', width=640,height=480)
mapCountryData( lrmapdata, nameColumnToPlot="position",colourPalette=op, xlim=c(-9,31), ylim=c(36,68), mapTitle='2000', aspect=1.25,addLegend=T )

The limits on on the x- and y-axes center the map on Europe. It is a process of trial and error till you get it right, and the limits need to be co-ordinated with the aspect and the width and height of the png file so that the map looks reasonably well-proportioned. Here  is the result (click to see in full resolution):

It looks a bit chunky but not too bad. Next, we have to find a way to show developments over time. We could show several plots for different years on one page, but this is not very effective:

A much better way would be to make the maps dynamic, or, in other words, to animate them. But this is easier said than done. After searching for a few days for tools that can accomplish the job, I settled for producing individual maps for each month, importing the series into Adobe Flash, and exporting a simple animation movie. The R code to produce  the individual  maps:

lr<-manifesto.position('rile', start=1948, end=2008, period='month')
lr$State<-recode(lr$State, "'Great Britain'='United Kingdom'")
for (i in 1:length(u.c)){
     lr.temp<-subset(lr, lr$Year.month==u.c[i])
     lrmapdata <- joinCountryData2Map( lr.temp,joinCode = "NAME", nameJoinColumn = "State", mapResolution='medium')<-paste('./maps/map',i,'.png', sep='') 

     png(, width=640,height=480)
     mapCountryData( lrmapdata, nameColumnToPlot="position",colourPalette=op, xlim=c(-9,31), ylim=c(36,68), mapTitle=u.c[i], aspect=1.25,addLegend=T ) }

And here is the result (opens outside the post):

Flash video of Left-Right positions (slow)

It kind of works, it has buttons for navigation, but it has one major flow – it is damn slow. It should be 12 frames (maps) per second, and it is 12 fps inside Flash, but once exported, the frame rate goes down (probably because my laptop’s processor is too slow). In fact, I can export a fast version, but only if I get rid of the control buttons. Here it is (right-click and press play to start):

Flash video of Left-Right positions (fast)

You can also play the animation as an AVI video (uploaded on YouTube), but somehow, through the mysteries of video-processing, a crisp slideshow of 8mb ended up as a low-res movie of 600mb.

The results resemble my initial idea, although none is perfect. Ideally, I would want a fast movie with controls and a time-slider, but my Flash programming skills (and my computer) need to be upgraded for that. Meanwhile, the Manifesto project could also update their data on which the animation is based.

Altogether, the experience of creating the visualization has been much more painful than I anticipated. First, there doesn’t seem to be an easy way to get a map of Europe (or, more precisely, of the European Union territories) for use in R. The available options are  either too low resolution, or too outdated (e.g. featuring Czechoslovakia), or require centering a world-map using ylim and xlim which is a problem because these coordinates are connected to the dimensions and the resolution of the output plot. For the US, and for individual European states, there are tons of slick and easy-to-find maps (shapefiles), but for Europe I couldn’t find anything that doesn’t feature huge tracts of land east to the Urals, which are irrelevant and remain empty with political data (which is usually available for the EU+ states only). Any pointers to good, relatively high-res maps (shapefiles) of the EU will be much appreciated.

Second, producing an animation out of the individual maps is rather difficult. Currently, Google Charts offer dynamic plots and static maps, I hope in the future they include dynamic maps as well. Especially because the googleVis package makes it possible to build Google charts from within R. I also found a new tool called StatPlanet which seems relevant and rather cool, but still relies on Adobe Flash and has no packaged Europe/EU maps. The big guns in visualization software are most probably up to the task but Tableau is prohibitively expensive and Processing is said to have a steep learning curve. Again, any help in identifying solutions that do not require proprietary software to produce animated maps would be much appreciated. I hope to be able to post an update on the project soon.

Compiling government positions from the Manifesto Project data with R

****N.B. I have updated the functions in February 2019 to makes use of the latest Manifesto data. See for details here.***

The Manifesto Project (former Manifesto Research Group, Comparative Manifestos Project) has assembled a database of ‘quantitative content analyses of parties’ election programs from more than 50 countries covering all free, democratic elections since 1945’ and is freely accessible online. The data, however, is available only at the party, and not at the government (cabinet) level. In order to automate  the process of extracting government positions from the Manifesto data, I wrote a simple R function which combines the party-level Manifesto data with the data on government compositions from the ParlGov database. The function manifesto.position() produces a data frame with the country, the time period, the government position of interest, and an index (id) variable. You can get the data either at a monthly or yearly period of aggregation, specify the start and the end dates, and get the data in ‘long’ or ‘wide’ format.

Here is how it works: First, you would need R up and running (with the ‘ggplot2‘ library installed). Second, you need the original data on party positions and on government compositions, and this script to merge them. Alternatively, you can download (or source) directly the resulting merged dataset here. Third, you need to source the file containing the functions.

Here are a few examples of the function in action:

### 1. Load the data file from the working directory or from the URL (default)
#cabinets<-read.table ('cabinets.txt',
cabinets<-read.table ('', ### 2. Load the functions from the working directory or from the URL (default) #source('government position extraction functions.R') source('') ### Use of manifesto.position(x, weighted=TRUE, long=TRUE, period='year', start=1945, end=2010) ### Inputs: ### x [the name of the Manifesto item] ### weighted [weighted mean of the government position or a simple unweighted mean] ### period [year (default) or month - time period for which the position is extracted] ### long [long (default) or wide version of the output data] ### start [starting year for the extraction; 1945 is default] ### end [end year of the extraction; 2010 is default] ### Output: A data frame with four columns - State, Year (Year.month), position [the actual position], id [Year.State(Year.month.State)] ### For details see the sourced file above ### Examples ## 1. Extract the left/right positions lr<-manifesto.position('rile') summary(lr) ## 2. Exatract the unweighted International peace position from 1980 until 1999 intp<-manifesto.position('intpeace', weighted=F, start=1980, end=1999) hist(intp$position) ## 3. Exatract the weighted Welfare position from 1980 until 1999 in a wide, rather than long shape - states are rows and years are colunms welfare<-manifesto.position('welfare', long=F, start=1980, end=1999) welfareT<-t(welfare) ##this would make the countries columns and the years rows. ## 4. Left/right on a monthly basis from 1980 till 1990 lrm<-manifesto.position('rile', period='month', start=1980, end=1990)

I hope you find the function useful. Feel free to e-mail any suggestions, remarks, reports on bugs, etc. If you use the function and the data, don’t forget to acknowledge the work of the people who collected the Manifestos and who compiled the ParlGov database.