10 Complex Visualisations
This week, we look at self-identified ethnicity across Inner London, using it as the basis for a treemap and a panelled set of histograms.
In these last two weeks, we work with the help of an AI assistant, Microsoft Copilot, rather than working through a fully worked example. You will be given real data, an end goal, and Copilot as a working partner, and asked to develop your own approach. We focus on producing visualisations here, but the same principle applies to any other way you might use these tools: check what a tool produces and understand what you are doing, including any intermediate steps.
10.1 Lecture slides
You can download the slides of this week’s lecture here: [Link].
10.2 Reading list
Essential readings
- Wickham, H. 2010. A layered grammar of graphics. Journal of Computational and Graphical Statistics 19(1): 3-28. [Link]
Suggested readings
- Cheshire, J. and Uberti, O. 2014. London, The Information Capital: 100 Maps & Graphics That Will Change How You View the City. London: Particular Books.
- Wickham, H., Çetinkaya-Rundel, M., and Grolemund, G. R for Data Science. 2nd edition. Chapter 3: Data visualisation. [Link]
10.3 Coding with Copilot
Suppose you want to understand how the population of Inner London varies by ethnicity, borough by borough. The data cover self-identified ethnicity across London, recorded in the 2021 Census at Lower Super Output Area (LSOA) level, and we will narrow this down to the 12 Inner London Boroughs.
| File | Type | Link |
|---|---|---|
| London LSOA Census 2021 Ethnicity | csv |
Download |
| London LSOA 2021 Spatial Boundaries | GeoPackage |
Download |
Load both files, and use Copilot to help with the parts you are less sure of, for example turning the raw counts into proportions, or reshaping the data from long to wide format. Check the result at each step rather than moving straight to the next one.
Example prompt: “I have Census data in long format, with one row per LSOA per ethnic group. Using R I want to reshape it so that each LSOA has one row, with a column for each ethnic group containing the proportion of the population in that group.”
By the end of this stage, you should have a single dataframe with one row per LSOA, restricted to the 12 Inner London Boroughs (Camden, Greenwich, Hackney, Hammersmith and Fulham, Islington, Kensington and Chelsea, Lambeth, Lewisham, Southwark, Tower Hamlets, Wandsworth, and Westminster), with a column for each ethnic group expressed as a proportion of that LSOA’s population, and a column identifying which borough each LSOA belongs to.
Check your row count against what you would expect. If it looks too high or too low for 12 boroughs’ worth of LSOAs, something has gone wrong upstream.
10.4 Assignment
With the dataset ready, now work with Copilot to produce two visualisations:
- A treemap showing the relative share of each ethnic group within a borough of your choice.
- A panelled set of histograms showing the distribution of a population group of your choice across all 12 boroughs, one panel per borough.
If you get both visualisations working, take the code for one of them and turn it into a function, so that it can be rerun without copying and pasting. Keep the parameter list tight rather than open-ended, and match it to the visualisation you choose, since borough and population group are not interchangeable across the two:
- If you are turning the treemap into a function: one parameter for which borough to use, and one for the fill colour.
- If you are turning the histogram panel into a function: one parameter for which population group to plot, and one for the fill colour.
A treemap fixes one borough and shows every group within it, so borough is the parameter that changes what it shows. A histogram panel fixes one population group and shows every borough, so population group plays that role instead. Borough is not a meaningful parameter for the histogram panel, since the whole point of that chart is to show all boroughs at once.
Ask Copilot to help you refactor your existing code into a function with the two parameters above, then test it by calling it with different values to the ones you used originally. If the result does not look right, the function is not actually finished, even if it runs without an error.
10.5 Before you leave
That is it for today, and indeed, you have now reached the end of Geocomputation! Over the course of this module, we have explored the fundamentals of spatial analysis, reproducible research, and, over the last two weeks, what it takes to use an AI assistant well rather than blindly. It is now inevitable: time for that reading list.