Treemapping the UK's migrant population

5 Apr 2016 08:04 GMT

It's been exciting seeing version 4.0 of D3 develop, and last week Mike Bostock announced that d3-hierarchy was now included in the alpha. This module provides various ways of visualising hierarchical data, including treemaps.

I have wanted to explore using treemaps for some time, as much of the data I work with could potentially be presented in this way, so this seemed like an ideal opportunity to start experimenting.

My first attempt is a treemap showing the foreign-born population of the UK broken down by country of birth. The countries are grouped into broad global regions, using a particular arrangement of the new country groupings the Office for National Statistics has recently introduced in reporting migration statistics. Within the group for the European Union, the EU14, EU8, and EU2 are grouped separately.

The figures are taken from the most recent quarterly Labour Force Survey, which is for the fourth quarter of 2015. They are estimates of all people born abroad who were living in the UK at the time of the survey, excluding two small groups: those born in British overseas territories, and those who did not fully specify their country of birth. (The latter group consists of people who, for example, said they were born in the USSR but did not say which current country that would be.)

The treemap itself is relatively simple and leans heavily on Mike Bostock's example code, with just a few presentational tweaks. But it's the first time I have seen this data (which is very familiar to me) laid out in this way. It was extremely simple to get this working and I am looking forward to delving deeper into d3-hierarchy to explore what else is possible.

Further adventures in treemapping the UK's migrant population

9 Apr 2016 14:05 GMT

Earlier this week I posted a treemap showing the UK's migrant population by country of birth. A common reaction among people who saw it was to wonder what the size of the UK's foreign-born population was relative to the size of the UK-born population.

To help put that in context I have produced a new nested treemap showing the population of the UK broken down by region and broad country of birth. The population in each region is grouped into those born in the UK, those born in other EU countries, and those born in countries outside the EU.

While it's interesting to see the data visualised in this way, the advantages of using a treemap rather than a traditional bar chart are much less obvious in this case. When showing the migrant population by individual country of birth, a treemap lets you compare data for a very large number of countries in a way that is much easier to gloss than a bar chart. It allows you to group countries into common geographical regions, which represent the group's aggregate size. And the arrangement of countries from largest to smallest in each group provides a good visual representation of the distribution of the population within the group.

In this case, the UK's migrant population is too small as a proportion of the total population to break down into individual countries of birth, or anything more than two or three groups. Arguably the most interesting thing about the visualisation is how small the migrant population appears relative to the size of the UK-born population in every region outside London. On the other hand, a treemap makes it harder to make exact comparisons between the size of the migrant population in each region.

In short, I don't think this treemap is as effective as the last one, but that is probably because it is less well suited to the data being presented. But the new version of D3 made it just as easy to produce this treemap as the last one, and I thought it was worth sharing for those that asked to see it.

An introduction to programming with Python for complete beginners

14 Apr 2016 21:14 GMT

Earlier this week I ran a workshop teaching basic Python to people with little or no programming experience. I promised on Twitter that if it went well I would share the slides, which you can download here in PDF or PowerPoint format.

This is the first time I have ever tried to teach anyone how to program from scratch, and designing the workshop was not easy. There is a basic minimum you need to know before you can do anything useful as a programmer, but expecting beginners to absorb a lot of theory before writing a single line of code seems like a mistake.

The joy of programming comes from seeing your code run. To this day I think there is something magical about typing a string of symbols and making something happen. So this workshop tries to give people that experience as quickly as possible.

It's built around typing very short code examples into an online Python interpreter in order to see the concepts being taught in action. When running the workshop I tried to give everyone enough time absorb what they were doing, to experiment with the code, and to test their intuitions about how it worked.

I felt this approach worked reasonably well, but I need to reflect more before deciding whether to change anything in future. In the meantime, here are the slides in case they are useful to anyone teaching or learning to code for the first time.