Showing posts with label election. Show all posts
Showing posts with label election. Show all posts

Thursday, 13 July 2023

A new UK constituency hex map

There are new constituency boundaries in the UK so we made a new hex map. This means that the ones used in previous elections have been replaced by a new set. There are still 650 constituencies but they are in many cases quite different so any election boffins/mappers will need to get used to them, and their new shapes and names, pretty quickly. Take a look at this interactive map if you want to compare them (will load slowly, is best on big screen). When is the next UK general election? Well, nobody knows the date but it has to be no later than 28 January 2025. Philip Brown and I knew all this was in progress because we keep track of these things - particularly Philip - so many months ago we began the process of creating a new hex map, which you can see below. After that I say a bit more about the process of putting this together. Here's the direct link to the geo files if you want a shp, gpkg or geojson of the new hex map. Don't like hexagons? See this new video on my channel for how to change them to other shapes.


The new hexmap - web version


Search constituencies by name

A bit of preamable

You can make these things automatically, programmatically, algorithmically etc etc but the results will normally be very sub-optimal. Why? It's because of the difficulty of putting the hexagons together in a 'least-worst' configuration. They are all in the wrong place, but some are less wrong than others. That is, hex maps are about portraying each area with a shape covering the same area rather than geographical accuracy. 

Why? Because sometimes we want to size things by population rather than land area, but this means we have to sacrifice overall shape and individual area locations. But you probably already know all about this if you're reading my blog.

Each constituency has (very roughly, and with a few notable exceptions) a fairly similar population. Here's what the Parliamentary Constituencies Act 2020 says about it.

The Act sets out a number of Rules in Schedule 2 which are relevant to the detailed development of proposals for individual constituencies. Foremost among these is Rule 2, which provides that – apart from five specified exceptions – every constituency we recommend must have an electorate (as at 2 March 2020) that is no less than 95% and no more than 105% of the ‘UK electoral quota’. The UK electoral quota for the 2023 Review is, to the nearest whole number, 73,393.

Accordingly, every recommended constituency (except the five ‘protected’ constituencies) must have an electorate as at 2 March 2020 that is no smaller than 69,724 and no larger than 77,062.


The four Boundary Commissions in the UK published their new electoral maps (after previously publishing the initial proposals) in June 2023 and then we finalised the process. There are a total of 650 constituencies, just like before, with the following number in each country of the UK.

  • England (543)
  • Northern Ireland (18)
  • Scotland (57)
  • Wales (32)


The process of making this hex map

The process of making the map involved the following things, with me proposing the idea to Philip initially because he's really an electoral genius with boundary knowledge that quite frankly I'm surprised can be contained in just one brain. Anyway, he took up the task and got to work and we have our initial 'final' set - though as you can see from the web map url we consider this a 'beta' release because we're very aware that we are capable of making mistakes, even if we did go through a fairly rigorous quality assurance process!

Okay, so here's what we did. Then below that you'll see some images of how this all worked, including a few WhatsApp screenshots as proof of the level of thought behind this (and probably also evidence that we may need new hobbies).

Here's how we did this
  1. Meet at Dunkin Donuts many months ago to discuss doing this.
  2. Create blank hex grid in QGIS.
  3. Agree that we should start with final shape in mind.
  4. Agree that out of all previous UK constituency hex maps Ben Flanagan's (Esri UK) shape was the best shape, so model ours on that.
  5. Agree that we should generate a unique three letter code for each hex - so that (e.g.) we can label each hex within the shape and because official names often too long!
  6. Get loads of sheets of A2 and A3 paper printed with blank hex grids on them.
  7. Leave Philip to do his thing.
  8. Meet to discuss from time to time.
  9. Let Philip get on with it, region by region (England) and then UK countries.
  10. Monitor initial proposals from Boundary Commissions.
  11. Come up with final configurations on paper.
  12. Spend day working together on converting paper into digital.
  13. Revise, tweak, move a few polygons, re-shape Northern Ireland, move things around a little bit.
  14. Check for errors, duplicates, typos, and suchlike.
  15. Check again, then generate geo files for sharing (shp, gpkg, gejoson).
  16. Make web map available, as well as file repo.
  17. Add ONS area codes as soon as they become available (not sure when this will be).

That is more or less it, but it took many months and most of the hard work here was done by Philip. 


Some photos and screenshots for anyone who might be interested

It was quite an interesting process. Working on paper was actually very useful so we'd recommend starting with a final shape in mind plus some big bits of hex grid paper if you are trying to do this yourself, but really all the hard work is in figuring out how best to arrange the hexagons. This is what takes so long. Imagine if you had a Word document with 650 text boxes in it and you move just one box - everything else gets totally messed up. Well it's a bit like that. A real headache. All maps are wrong. All hex maps are wrong. But we created the least-wrong hex map we could and we hope others might use it and find it useful.

Happy mapping!
























Thursday, 19 January 2023

Animating a proportional symbol map in QGIS

Many people who read this blog will be familiar with Karim Douïeb's fantastic 'transition between surface area of US counties and their associated population' map, shown below.

I wanted to see if I could create something a bit like this in QGIS, using a geometry generator approach, so that's what this post is about. My end result is shown below, and read on for more information about my method. See the notes at the bottom of the page for a bit more detail. The version embedded below will be a bit small, so here's the full size, high-resolution mp4 if you want to take a closer look at it.



What's a geometry generator in QGIS?

In QGIS you can style layers in the normal way, as in any GIS software - e.g. by using a blue fill on a polygon and a white outline - or you can use the geometry generator option to style a layer in a different way. For example, if you had a set of points representing populations, you could turn them into spikes with the height based on their populations. 

You could display lines as a series of points, and all kinds of other options, all without having to create any new files. Or you could convert areas into proportional symbols, as I've done above.

Okay, so you may have read this and still be like 'what the what? what the heck does this mean?' and that's pretty normal actually because it's not necessarily an easy concept to grasp without seeing examples. That's why I created a sample file where you can drop it straight into QGIS and play with different geometry generator styles, as in the tweet/ thread below.


You can get really pretty fancy with geometry generators in QGIS and do all sorts of interesting things, some of which you can easily find if you search for geometry generator qgis on Twitter. 

The thread below is another example of what I'm talking about here - it ends up with me making a tartan t-shirt based on a geometry generator style and some point data in QGIS!


Okay, fine, but could we create something like Karim's animated map in QGIS? Well, I tried and I think I got reasonably close, so read on for more about it.

Polygons to proportional symbols with QGIS geometry generator + Atlas

Okay, first things first - if you want to replicate this style, you can find the QGIS project file plus the individual map layers in my training data folder - directs links to each file are provided below. Whereas Karim did this for the entire US, my example only includes the lower 48 states. If you already know what you're doing with QGIS this will be fairly straightforward but anyone with a bit of experience should be able to download the files and replicate my steps. Here are the files you'd need to replicate my work.

If you want to replicate my project exactly, you'll also need to have the Comfortaa font installed because that's what I used for the labels and in the Print Layout. You'll also need to open the Print Layout in the project and make sure you activate the QGIS Atlas (via the Atlas menu then Preview Atlas). I did this in QGIS version 3.24 so if you're having any issues try using the same version, or a later one. Last of all, if you want to add the QGIS logo like I have, you will need to change the file path for the Picture in the print layout. I put the QGIS svg logo file in the same folder as the files above.

As you move through the Atlas page by page, each of the counties changes from a polygon to a proportional symbol, from west to east, with the size of the symbol based on the number of votes in each county. This is not perfect, but it's a more proportional representation and it's all about testing the concept here. This is what it looks like half way through the set of QGIS atlas frames.

Half way through the animation

Once I got everything set up, I exported each page of the Atlas as a single png and then combined it into an mp4 as an animation, using ffmpeg. I've written about that process in a previous post. For the final version I added a pause at the end, then reversed it so it loops back and forth.

So what about the QGIS project file itself? Well, if you download it you'll see it contains:
  • A US states layer, to show the state outlines - simple black colour outline
  • A US cities layer, filtered to show a selection of cities across the US, and also labelled
  • A grey US county backdrop layer so that when the polygons turn to proportional symbols we still have some background behind it
  • And on top of the grey US county layer we have the red/blue county layer showing which party won in each county at the 2020 US election. This is the layer that has the geometry generator style in it. 
  • Plus the QGIS logo svg in the bottom right of the print layout. 
If you want to look at the all-important geometry generator style, just go to the Layer Properties for the red/blue us-election-2020-lower-48 layer and then double-click on the blue colour patch symbol then Geometry Generator to see the geometry generator style for the blue areas and then do the same for the red areas, as shown below. 

You can also access this via the Symbol dropdown in Layer Properties


This is the geometry generator style I used - it's pretty basic, but works well:

CASE

WHEN x($geometry) <  @atlas_pagename 

THEN  buffer(centroid( $geometry),7000+ "total_votes"/30 ,50)

ELSE

$geometry

END

What does it do, and how does it work? Well, the first bit after the WHEN uses the x coordinate of county centroids to change the shapes from west to east - this is because I used the longitude of each county as the Atlas page name. That's why @atlas_pagename appears in the expression. You'll need to think about this for a while if you're not used to how the Atlas tool works in QGIS but if you look at the Print Layout you'll see each page is named using x($geometry).

The next bit draws a buffer around the centroid of each county, to 7000 metres, then scales it using the total vote count, divided by 30 (otherwise the circles are HUGE, but I did experiment with this and scaled it loads of different ways). The 50 value just makes the circle smoother. Why 7000 metres for the buffer? Well, if it's much smaller then you can't actually see it at the scale I'm mapping at. 

The ELSE $geometry bit just says to QGIS to draw the polygon as usual until the Atlas page name (which contains the longitude) meets the WHEN condition above.

Confusing? Yes, probably if you've not used this before but feel free to download the project and have a go.

You'll also notice that in the Atlas tab I've done some other things, like set the page name using the format 0001, 0002, 0003, 0004 and so on. 

This is what the Atlas layout looks like at frame 2000, below.

What it looks like in the QGIS Print Layout


Okay, so can we create an animated proportional symbol map in QGIS? Yes, we can. 

Is it as cool as Karim's? No, but it does demonstrate the power of QGIS geometry generator styles and shows the kinds of things that can be done - and that's what this post is all about. 

This is example is fairly simple really but if you've not used QGIS in this way before it can be quite confusing - that's why I shared the simple geometry generator file plus the more complex project file shown here.

Want to replicate this but can't quite get it all to work? Feel free to get in touch.

Notes

If you want to actually create new geomtries (e.g. a new shapefile or geopackage) using a geometry generator expression, you can do it via 'Geometry by expression' in the Processing Toolbox.

Are the proportional symbols sized exactly to match the population? No, because the size is based on the buffer radius, but if you use a bit more clever maths in the expression you can get it spot-on. But if you do this, the smallest symbols will likely disappear.

What's the point of all this? The point is to test what kind of things are possible with geometry generator styles in QGIS and to share this with people who might be interested.

That's all for now. I may add further notes if there are any questions but I'm putting this post here as a more permanent resource for anyone interested in how to do this kind of stuff.

Sunday, 9 October 2022

Cometmaps

In one of my many 'playing around with map stuff and then posting it on twitter' adventures, I recently posted a kind of comet map - see below. This started off as something completely different but once I had the basic idea I then wondered what kind of data I could apply it to, and that's why I did it to the UK political map of 2019. Read on below for how I did it, as well as how you can replicate it pretty easily in QGIS. Scroll straight to the bottom if you're just looking for the 'how-to', as well as a bit more on how this kind of thing might work on a US county-level election map.

First of all, this was done in QGIS. I'm sure it could be done lots of ways, but I did it in QGIS using something called 'geometry generator', which is basically just a little bit of code that can be used to style things more fancily than just clicking a button and selecting a colour and shape. 

My starting point was actually just to see if instead of displaying things as polygons I could display them as lines that went from one corner of an area's bounding box to another - in this case from the far south-west to the far north-east corner of a shape's bounding box. That was easy enough - and the result is shown below. I did it with UK local authority areas, then moved on to doing it with constituencies - which you can grab from my Automatic Knowledge resources page.

A basic line, within each area's bounding box

Then I thought about applying a random degree of rotation to each line, just for the sake of it, and that's what you see below. This is probably not that useful unless you want to make a map that looks like a pile of sticks but all the same it's interesting to see that it's possible and perhaps I'll find a use for it one day. 

Big pile of red sticks drifting into space

So then I went back to no rotation and thought about buffering the lines, but using a tapered buffer so that one end was thick and the other wasn't. I applied this to each area and also used a gradient fill so that the colour faded along each shape. The result of this is shown below. This one was also done on local authority boundaries rather than constituencies because I was playing around with both at the time - but then I wondered about applying it to a political map and doing something more interesting, so the cometmap came to life. 

A cometmap emerges from the darkness


The result was that I decided to use geometry generator in QGIS to do the following, based on the results of the 2019 UK General Election - and my goal here was to use the comet trail as the main device in the map to show who came second and how far behind they trailed. I realise some people look at the maps and perhaps see the opposite but for a little map experiment I thought it was a) interesting and b) potentially useful (probably with some further development).

  • Use a circle in the centroid of each constituency, using party colour to indicate who won that seat.
  • Use a tapered buffer behind each coloured circle, with the colour of the party who came second.
  • The length of the comet trail is dictated by the winning margin - so if a party is WAAAAAY behind the winner then it gets a longer trail. So this map draws attention more (deliberately) to the second placed party. But of course any of this can be edited.
  • The size of the circles and buffer is a few thousand metres but of course that can be adjusted too. See the results below.
Dot with no trail? Means it's very close

Loooong blue trails? Conservatives waaaay behind

Mostly short trails = mostly quite close results

THE LIBERAL DEMOCRATS ARE COMING!!!!

Okay, so that's about it. 

Read on if you're a map nerd and you want to replicate the style yourself.


How to replicate this style in QGIS

  1. First of all, you'll need to grab the UK General Election 2019 results file from my Automatic Knowledge resources page. Use the GeoPackage because it's easiest.
  2. Add the file to QGIS. 
  3. Optional step. For exact duplication of my maps, make the QGIS background very dark grey (e.g. #111111) and make duplicate the UK general election layer and make it dark grey, both fill and stroke colour (e.g. #333333) so that when you make the comets they look brighter and have a dark backdrop and you can also get your bearings from the plain dark backdrop. 
  4. Download the cometmap layer style file to your computer. This is just a standard QML file and you'll apply it in the next step.
  5. Go the Layer Properties for the layer you want to apply the cometmap style to and then via the Style button at the bottom of the Layer Properties window, and then it's Load Style... browse to the cometmap-ukge-2019-example.qml file on your computer, then it's Open, Load Style and OK - and that should be it!
  6. Once you've done this you can inspect the properties of the style yourself and edit them if you want to - see screenshot below.
How the trail is generated - rotation set to zero right now


Note that I am using a geometry generator twice in the screenshot above - once to create the circle and once again to create the trail. You'll see that the colours are set using an expression - if you click Simple Fill you can see this when you click the little Expression button (see below). Note that this is done both for the trail and the circle.

The '97' in the html colour values sets the opacity


Could you apply this to, say, a county-level US election map? Yes, but I think it would probably require a good bit more thought otherwise you'd end up with a really wild map. But here are a few examples.

File these under 'hmm' for now.

Done very quickly, just to test the method

You can see where this needs work - but it could work

Just a few tweaks needed here!

That'll do it for now

Needlemaps - the next frontier

I had a bit more of a think about it all and for the US I wanted to see if I could create a kind of needle or dial that showed which way a county leaned. using the 2020 US election results file. Well, turns out that this works reasonably well. Not perfect but it's a good start. See below for the results and then if you want to replicate it yourself and then play with my settings, download the qml needlemap style file for QGIS and then apply it to the election results file and have lots of fun.

Lots of ways this could be edited/improved


Yeah, not surprising

Big 'lean left' energy going on here

Actually quite interesting here I think

Lots of interesting stuff here, for sure


Note that in the needlemap style above, size = scaled to population, roughly, but of course I had to make some a minimum size otherwise they would be invisible, so I also added opacity by population to make them super-faint if they are tiny. Colour = blue for lean Dem, red for lean GOP. Lean angle is set from the Dem/GOP ratio from 2020.

Thomas Gratier on Twitter suggested we could call these pinball maps, and that's also a good fit as the needles look very much like flippers on a pinball machine.


Friday, 14 May 2021

Far too many words about a chart

This is a bit of a long read, because I wanted to put down my thoughts on a chart I made that has been quite popular and quite widely shared. See below for one version of this chart - it ranks all 650 UK Westminster parliamentary constituencies by deprivation and colours them by which party won the seat at the 2019 General Election. You can skip straight to the data and charts folder now if you want, but if you do, it's probably best if you also read the notes at the bottom of the page. Because this is a chart made of blocks, or bricks, and because of recent 'red wall'/'blue wall' media talk I'm going to call this a wallchart, but you can call it whatever you like. If you do like reading about charts and dataviz and the thinking behind them, read on. I cover all the small things.

Click to see it full size

Background

I will not go on too much about the backstory, but I'm here to tell you that there have been quite a few votes on things across the UK in recent years. This is something you may have noticed, particularly if you were up all night watching, waiting, or commiserating at any recent election. Because of all the votes there have been lots of maps, lots of data and lots of news. Some good stuff, some confusing stuff and probably just too much stuff. But anyway, after the 2017 UK General Election in June 2017 I wrote a piece on here with some maps and charts. Almost as an afterthought, I said to myself 'I wonder what it would look like if you took all 533 English constituencies, turned them into blocks, ranked them by deprivation, and then coloured them by the party that won the seat'. Then I thought, 'how quickly can I do this?' So, I did it very quickly and messily in Excel - see below for what the first one looked like and a screenshot from the original Excel file.

What's 533 divided by 10?


Some immediate observations about this chart that came to mind at the time: i) it's annoying that there are 533 rather than 530 constituencies in England - neat charts > representative democracy; ii) this chart tells us something that is blindingly obvious but even so it's also strangely striking; iii) 'hey, what's that blue block doing on the left hand side'? (it's Walsall North); iv) I didn't realise the orange blocks would nearly all be on the right half of the chart; v) I need to figure out how to deal with the fact that 533 doesn't divide by 10 neatly and maybe make the top of the chart nice and flat.

Excel?! #$@&%*! Excel!!?? Say it ain't so


Next versions

I really didn't think much of it at all after I hit Publish and never planned to come back to it, but at some point in the year or two that followed, Danny Dorling got in touch with me about it using it and then I did new versions for different years, including ones for the UK that were much neater because of the fact that there are currently 650 constituencies and this divides neatly into 10 columns of 65. I also changed the colours, added more labels and some versions had constituency names as well. The initial one used deprivation data for English constituencies produced by the always-excellent team at the House of Commons Library. For the earlier UK versions I used UK-wide deprivation data produced by Abel et al. (2016) to calculate the ranks. 

For most versions of the chart, including the UK ones, I've had to calculate constituency-level deprivation myself using a population-weighted method, aggregating up from small areas (LSOAs in England and Wales, data zones in Scotland and SOAs in Northern Ireland). A big hat-tip here must go to my collaborator and all-round political data boffin Philip Brown for prompting me to come back to this and do new versions. When the 2019 General Election came round I decided to dust off the old files and make a version that looked much nicer. The reason I've come back to this again now is because Alex Parsons recently published a new set of UK-wide deprivation data, based on the earlier work by Abel et al. 

The left hand column is turning blue


This was the 2017 General Election edition

It took a while to put the data together for the different years and although I would have loved to put together one for earlier years - particularly 1992 and 1997 - it would have taken me too long to do it.

Read on below for more on the design stuff


Since I did the first one of these in 2017, other people and organisations have done their own versions using the same concept. I am not sure if it was done before that, but I haven't seen one like it. All I do know is that I got the original idea from a chart Owen Boswarva made in relation to age and party colour. 

Here's a version that the Economist created (below) - horizontal rather than vertical and much more elegantly executed. It was in their 'Who are the Conservatives’ new voters in the north?' piece from December 2019 - which I took a picture of in the print edition just because it's nice to see things in print. I had to travel a further from home than I expected to actually find a print copy of the Economist because none of the local newsagents near me in Sheffield Brightside and Hillsborough (left-most column) stock it, but that's another story. 

This is a good place to mention the ecological fallacy, because I am certainly not claiming I am poor, or deprived - this is just a nod to the fact that internal variation obviously exists in all areas, even if the overall ranking is a good representation of the overall pattern across the UK in terms of relative deprivation by area.

Lovely!

Call me old fashioned but I do like print

There are also other versions out there, including a remain/leave by deprivation one that Helen De Cruz did - copied below. I thought this one was really interesting, particularly column 10.

Column 10 is clearly the most remainy

There was also a version of the chart looking at age and deprivation - this was done by the Resolution Foundation in December 2019 and can be found in this twitter thread (I've pasted the chart below as well). I decided to do an age one in my most recent iteration - see below for that.

Very nicely done

I have also created a dark mode version of the latest chart from 2019 and a chart ranked by median age as well, so I'll put these ones below too. You can see this in my more recent twitter thread about it.

Turn the lights off!

Age rank gives us a similar pattern

Design

The legendary Andy Kirk very kindly noticed one of the things I did in earlier versions of the chart so click that link for a bit of independent insight on one of the details. Here I will set out a few reasons why I think this chart connects with people - and why it also makes sense to me. One of the main reasons is that it builds upon some things that are hard-wired into our brains already.

  • Rank: ranking things is not always a sensible idea and it's always somewhat fuzzy. Things get collapsed into categories made by people and this can mask internal variation. However, even if ranks can be quite a coarse measure, the constituency ranks by deprivation are more or less what we might expect for England or the UK as a whole. The places with the most 'poor' or 'deprived' neighbourhoods are on the left of the chart, with the wealthiest areas on the right. Also, and fundamentally, ranks are easy to understand, so this is not much cognitive work for the reader, once they know how the chart is laid out with the most deprived areas at the top left and least deprived at the top right - and this requires only minimal labelling. 
  • Colour: this one is of course more context dependent in that UK readers (or those who follow UK politics) don't need more than a split second to interpret the colours, without a key. We see red, we see Labour, we see blue we see Conservative, we see yellow, we see SNP, and so on. There aren't many occasions when we can do this with colours but political charts and maps are one example where we can. The cognitive load here is again quite low, I would argue. I will just add that I've tweaked the original colours because the red/blue combo was blinding in the first chart. My colours are a mix of commonly used ones (e.g. on BBC election coverage) plus a bit of artistic licence. 
  • Position: The general idea is for this chart to be more about the forest than the individual trees. Having said that, being able to position individual areas on the spectrum from more deprived (left) to less deprived (right) is very important. It also matters symbolically that the red areas are on the left, and blue on the right because this is a visual match for the traditional left/right political divide. Again, we can argue with definitions and concepts here but having Labour on the left and the Conservatives on the right matches what is already hard-coded in our brains if we follow politics even just a bit.
  • All the small things: there are lots of little things I've tried to do with the different versions of this chart to make it easier to digest, but without overwhelming the reader. One example is the faded axis labels on the left and right of the chart (below). I did this because I only really wanted people to be able to understand how the ranking worked, but without introducing any cognitive overload. I also don't want to put too much stock in individual rankings - I'd rather people saw the groups of 10 (labelled across the top) as more indicative of relative socio-economic status. That's also why the label colour is lighter for the individual blocks. The number fade thing was something I got from John Burn-Murdoch on twitter but I can't find the original post on that. So, the faded axis numbers are very much there so readers can get what's going on, but without it being too much of a focal point or distraction. 
  • Notes, etc: with this being the internet, there are small dangers associated with doing this kind of thing. Quite often people take things without attribution or context and share them with friends and followers as their own (even academics who ought to know better). People also see what they want to see - particularly with politics and causal links on a chart like this. The idea behind the chart was simply to see what the pattern looked like. I'm not trying to identify causal links here, but clearly people will do this anyway. Looking for causal links is a different kind of statistical activity, but this chart raises such questions with people and that's to be expected. Anyway, in order to avoid some of the problems with no-context sharing, I try to put enough text on the chart to explain a) what it is; b) how it was made and c) data sources. I usually add my name as well so that if someone wants to find out who did it they can get in touch - this would be more complex if my name was John Smith - but thankfully there aren't that many Alasdair Raes doing weird colour charts these days. Still, people will crop your name off because this is the internet.


There are plenty of things I could improve about the chart- and I've tried to keep doing that - but at the same time this wasn't part of my day job (work sucks, I know) and it wasn't for any particular project so I can't invest too much time in it (he writes, whilst writing War and Peace instead of finishing the presentation for next Tuesday). Having said that, there are a few final points I'd make on all the design-related stuff.

  1. Doing this in Excel might be okay for a quick-and-dirty experiment but it's clunky and messy and every time I go back to the original I am confused. It also takes me ages to find the original files. Having said that, I'm not bothered about what tool I use to do a job so long as it works - and there is nothing wrong with Excel, used properly. I like to think I follow 'the law of the job' rather than 'the law of the instrument' but even so this was a messy mess first go round. It started off as a bit of Excel formula, pivot chart, conditional formatting and a few hacks and it worked, and that's okay.
  2. After Excel I normally used GIMP to add some text and other bits. Again, fine but not optimal. I think in previous quick versions I even drew some arrows in PowerPoint and I'm not even sorry because it worked fine and served a purpose.
  3. I don't really like to label the individual blocks because the chart idea wasn't about that, plus some constituency names are very long and the font size has to be small. But I do like to think about user needs so some versions have them because people always ask. There's also a searchable html version so you're only a quick browser search away from finding your area.
  4. Most importantly, the way I have done this to date is pretty sub-optimal to say the least but then sometimes sub-optimal things happen and you get locked in to them. 

So, I thought to myself... why don't you try to make this less bad and also sharable? Good idea. But how? Read on to find out and grab the data for yourself.


Wallcharts for everyone
I normally work with spatial data but the chart I'm talking about here is non-spatial - it's just a series of ordered blocks and where they sit in the chart bears no relationship to their geographic location in the real world. Nonetheless, what I decided to do was keep it simple and create a 10x65 GeoPackage that covered roughly the same areas as the UK and with the constituency deprivation rank number assigned to each block - see below for what this looks like with the standard UK election map on top of it. Once I'd created the 10x65 grid I prepared a separate spreadsheet with all my other data in it - including age, ethnicity and so on. I then joined this to the 10x65 grid to make the final GeoPackage.

The 10x65 GeoPackage can be found in this web folder - I've also shared it in different formats as in the hope that it can be more widely used (shp & geojson). When you add it to QGIS it will be coloured according to the party that won each seat in 2019. I do realise that for non-GIS users this might not be ideal, but you can easily take one of the existing versions and convert to a more suitable format for your own needs. There's also a qml file in the folder that you can use to style the layer, as well as one svg that I extracted as a test.

This is simple, but works well


Just in case you download the UK 650 block file and are confused by the column headings, here they are:

  • fid - just a numeric identifier, which can be ignored
  • DEPRANK - the rank of each constituency based on Parsons' 2021 UK small area deprivation data, aggregated up to constituency level (by me)
  • CODE - ONS constituency code
  • CONSTIT - constituency name, upper case
  • NAME2019 - constituency name
  • COUNTY - the county a constituency is in
  • CTRY_REG - the UK country or English region a constituency is in
  • COUNTRY - the UK country a constituency is in
  • GE2010, GE2015, GE2017, GE2019 - the part that won in each of these years
  • AGE2019 - the median age of each constituency in 2019
  • AGERANK the age rank of each constituency in 2019 (1 is youngest)
  • POP2019 - the population of each constituency
  • MINDECILE - the minimum UK-wide decile any single LSOA/DZ/SOA within a constituency is in (1 being the most deprived)
  • MAXDECILE - the maximum UK-wide decile any single LSOA/DZ/SOA is in (10 being the least deprived)
  • AVRANK - the average rank of all LSOA/DZ/SOAs in a constituency - where 1 is most deprived and 42,619 is least deprived (so, e.g. an average rank of 4262 would mean that the average area was among the 10% most deprived nationally)
  • POP2011 - the population in 2011 (relates to the indicators below)
  • WHITE2011, MIXED2011, ASIAN2011, BLACK2011, OTHER2011 - the number of people in each ethnicity group from the 2011 Census (data published by the House of Commons Library)
  • WHITEPCT, MIXEDPCT, ASIANPCT, BLACKPCT, OTHERPCT - same as above, but % rather than total number
  • WHITERANK, MIXEDRANK, ASIANRANK, BLACKRANK, OTHERRANK - this ranks all 650 constituencies according to ethnicity, so that an area with a WHITERANK of 1 has the highest % of white population (as of 2011, we don't yet have 2021 Census data, so keep that in mind) and a WHITERANK of 650 has the lowest % of white population - and so on for the other groups.


I'm almost done here, but before I wrap up here are some different versions of the chart - now much easier to create having done the hard work of putting it together in a more suitable format. All I need to do is apply a simple filter and I can get all sorts of interesting charts out of it.

The overall 2019 chart

2019, just for England

2019, just for Scotland

Coloured using 2010 results

Constits that are 25% + non-white

The 100 oldest constituencies

Lab in 2017 but Con in 2019

What colour the 2010 Lib Dem seats are now

I've put the high resolution (300dpi) versions of these charts in the new wallchart folder I created for this project, so feel free to use them as you wish. 

Well, this was quite a long post so if you read all of it then please accept my thanks and congratulations.

This was mainly about all the small things, so if you noticed the Blink 182 song references, well done - carry me home! 


Notes

The deprivation ranking is somewhat England-centric. You can read more about the new UK deprivation data I used for the new charts on Alex Parsons' repo for the project. This new iteration is all possible because of the great work Alex did. If you want to follow the method then you should definitely read his notes on this - as well as the bit on mapping (which I provided some of the text for). There are four different files you could use to create a UK-wide constituency ranking. I used the UK_IMD_E.csv file, but the overall pattern is not likely to change much when you use the others. I also used the most recent mid-year population estimates (2019) for weighting.

The individual ranks of constituencies are likely to move slightly up and down if you use a different method but, on the whole, I am confident they are in the right place. 

Feel free to use, re-use, improve or otherwise adapt this - I know there are many, many people with better skills and ideas than me so this is very much a starting point.

If I spot any typos or other errors I'll back later to clean them up.