Using the ONS postcode file to get the 2015 General Election Results by unit postcode

I was wanting to do some analysis on the results of the 2015 UK general election. In a lot of the datasets I use the only geographical marker I have is the unit postcode. So before I can do any analysis on the results I first need to map all of the UK constituencies onto a postcode list. Luckily for me this can be done using the ONS postcode file which has, amongst other things, the Westminster Electoral Constituencies for all UK unit postcodes. I would normally do this in SAS but since I'm learning R I thought I would do it there first.

First I need to get my data:

  • ONS postcode file

Mapping in Excel

Over the past year I've been having a play mapping things in Excel, not the best tool for doing this I know but it does the trick. Mapping the data directly from Excel has the advantage that I've my data is already in Excel. I would like to do the same exercise in R but that's for another day once I get to know R better.

The method I used is based on tips and methods used on Chandoo and Clear and Simply.

My output looks like this:

Which looks pretty good to me.
Read More