Creating Cartograms using QGIS 2.18


First a confession, I don’t like cartograms, at least not the kind where complex boundaries are warped sometimes beyond recognition. However they do have their place and where there aren’t the extremes in the data a cartogram can be a great data visualisation. It is outliers or extreme values that cause the maps to be distorted beyond usable recognition, and therefore look bad (see below).Cartogram PaullHennig2016WorldMap.OAha.CC-BY-4.0

By John Paull and Benjamin Hennig ( [CC BY 3.0 (], via Wikimedia Commons

Anyway, if your data isn’t going to produce a map like this then you can use the Cartogram plugin in QGIS. This allows you to quickly turn your map into one that removes the misrepresentation of small areas hiding large values.

The Cartogram Plugin

To start creating your Cartogram you will need to add in the Cartogram plugin using the Manage and Install Plugins interface:

Installing QGIS plugins

Search for Cartogram, once installed you should see it in your list of plugins:

Installing the Cartogram Plugin

The Data

We are going to use the London Boroughs for this exercise which we are going to scale by the number of people that voted in the EU Referendum.

The data can be downloaded here in GeoPackage format:


The Method

The plugin makes this all super simple, just start the plugin by clicking on the Vector menu at the top of the screen then Cartogram and Create Cartogram:

Opening the Cartogram plugin

A very simple interface opens where you select the data you want and the attribute you want to scale it by:

Cartogram plugin options

In this example select the LondonBoroughEURef as the Input layer and then the Votes as the Area field.


Before you click OK it asks you how many iterations to perform. The default is 5 and this is about right. After this the difference you get is increasingly marginal, with the difference between 10 and 15 iterations imperceptible in most areas.

Base data for Cartogram of London
Base Data
1 Iteration Cartogram of London
1 Iteration
2 Iteration Cartogram of London
2 Iterations
3 Iteration Cartogram of London
3 Iterations
4 Iteration Cartogram of London
4 Iterations
5 Iteration Cartogram of London
5 Iterations
10 Iteration Cartogram of London
10 Iterations

You might be able to see that there isn’t much difference between the change from 4 to 5 iterations and 5 to 10 iterations. However there is a much bigger wait for creating a 10 iteration cartogram than there is for a 5 iteration one. All these images have been combined here with the darkest being 10 iterations and the lightest the original London Boroughs:

Multi layered Cartogram of London
London Borough Cartograms: Each borough is scaled by the number of votes cast in the EU Referendum of 2016. The darker the line the more iterations run by the Cartogram plugin in QGIS: 0, 1, 2, 3, 4, 5, 10.

IMPORTANT NOTE: Each time you run the Cartogram Plugin it creates a new virtual layer called Cartogram. You will need to save this if you want to do anything with it, or not loose it if you close QGIS without saving.

Final Tips and Tricks

If you want to make a cartogram out of data that has got outliers or extreme values there are few things you can do to prevent the distortion affecting your the usability of the map.


We have seen that the plugin will provide you with intermediate steps between the base data and the final number of iterations you choose. By generating a map for each of the intermediate numbers of iterations you can create a series that can be animated. Just use the Save as Image… option from the Project menu to create a .png file for each one:

Save as Image in QGIS Project menu

You can then use your favourite animated GIF maker on the internet (just google it) or put it into any movie maker package you have access to. The result will show people how the areas have changed and explain areas where the warping makes them unrecognisable:

Animated Cartogram of London
Animated GIF of the London Boroughs. The map shows most voters are in the central boroughs except the City of London which has the least.

Tone down the effect

There was a very interesting paper at the GISRUK 2017 conference by Richard Harris, Chris Brunsdon, Martin Charlton and David Manley:

Tackling the Curse of Cartograms: addressing misrepresentation due
to invisibility and to distortion

In it they describe a few ways that will help mitigate the problems of extreme cartograms. However you may need to use a different method from the cartogram plugin to achieve the desired effect.

Creating a statistical dot density map with QGIS

Dot Density maps:

These maps display the density and distribution of a phenomena over a geographic area. The markers, usually a dot or cross, represent the occurrence or an aggregation of occurrences which are then randomly distributed across distinct regions of the map. Colours can be used to represent different classifications to add an extra dimension to the map.

The example above shows votes to remain (red) and leave (blue) the European Union in the London Boroughs. Each dot represents 100 votes and these have been randomly scattered within each borough to represent the density of votes.

The Data

For this exercise we are going to use a geopackage which contains the outlines of the London Boroughs.  The attributes of the boroughs include the number of votes to remain and the votes to leave the EU. You can download the data here:

London Boroughs EU Referendum Results

Contains OS data © Crown copyright and database right (2017)

The Method

Field Calculator

Before we can start generating the dots on the map we need to create a column with a reduced number, as there were too many votes cast to give each one its own dot. To do this we will use the field calculator to create new attribute columns with the numbers of votes each way divided by 100.

  • Right-Click on LondonBoroughEURef in the table of contents and select Open Attribute Table
  • Click on the Open Field Calculator button above the table: 
  • You will need to set up the Field Calculator as follows:

  1. Make sure the Create a new field option is selected and enter the name 100 Leave Votes.
  2. Make sure the Output field type is set to Whole number (interger) and the Output field length can be left at the default 10.
  3. The expression needs to be: “Vote_Leave” / 100 you can user the Fields and Values section to the right to make sure you get the right field names and quote marks, just double click on the field name you want.
  4. Click OK.

Now repeat this process to create a similar column for the remain votes, call the column 100 Remain Votes. The table should now look like this:

Click Save edits  then toggle out of Edit mode 

Random points


Now we have the reduced quantities we can use QGIS to randomly assign points across each area.

Select the Random points inside polygons (variable) from the Vector > Research Tools menu.

Fill in the values as follows:

  1. Although we are making a density map we are going to use the Points count Sampling strategy.  This will assign the number of points in the Number field to each polygon.
  2. Choose 100 Leave Votes to be the Number field. Don’t choose Votes_Leave or Votes as you will then be creating a huge number of points in each polygon!
  3. Set a Minimum distance of 1 – 10 (map units, metres in this example) It is good to not have the points overlapping but not essential as we will mitigate this at a later stage. If you set this too high there may not be room for all the dots in the smaller boroughs.
  4. Save your file as a new Geopackage (or shapefile if you want to). These files will be quite big so it is best not to create a temporary layer.
  5. Click Run.  It will take a while as the algorithm has to cycle through the 33 boroughs.

Once the process has finished you will have points all over the map within the boundaries of the London Boroughs.  However the new layer added will be called Random Points in the layers panel.  We will need to change this before we create a similar file for the votes to remain.

  • Right-click on Random Points in the layers panel.
  • Click Rename and change the name to be 100 leave votes.

Now rerun the Random points inside polygons (variable) for the remain votes. Use the same process as above, but use 100 Remain Votes as the Number Value, call the new geopackage Remain Dots, and finally rename the layer in the layers panel to be 100 remain votes.

The map will now look something like this:

Styling the Map

As it stands this map is rather useless, the points are all overlapping and you can’t see the leave votes as the remain all lie over the top of them. Thankfully we can use the power of QGIS to style the points in a way that makes gives equal emphasis to dots from each layer.

First let’s style the London Borough polygons so that they don’t interfere with the dots.

  • Click on the LondonBoroughsEURef in the layers panel to highlight it and then press F7 on your keyboard to open the Live Style Dock on the right side of the map.
  • Click Simple Fill at the top of the Layer Styling panel.
  • Change the Fill to Transparent.
  • Change the Outline Width to be 0.6

The Outlines will now be clear but there will be no fill colour to interfere with the dots. We can now move on to styling the points.

We need to reduce the size of the points, so the map isn’t too crowded and give them a good colour. We also need to set a blend mode to account for any over lapping points.

  1. Use the drop down menu at the top of the Layer Styling panel to change the layer to 100 Remain Votes.
  2. Click Simple Marker to reveal more options.
  3. Set the Size to be 0.6 (Millimeters).
  4. Set the Outline Style to be No Pen.
  5. Set the Layer lending mode to be Multiply
  6. Set the Feature blending mode to be Multiply
  7. For Fill, click on the colour swatch.

We want to set this as red but we want to take down the saturation. This is to allow overlapping features to have a stronger colour; either a strong red where two features in the same layer are blended or a purple where there is overlap with the blue leave dots.

By picking colours of the same intensity we have also made sure that the map has minimal bias to one colour or the other. This is also maintained by the use of the Blend modes which mix into purple and so minimise the bias where one dot may have overlapped another of a different colour.

On the colour chart:

  1. Set R(ed) to be 255 (Full) and G(reen) and B(lue) to be 0.
  2. Go up to S(aturation) and bring this down to 70% making the red lighter. You will notice that the G and B values increase to 76.

The colour now has scope to increase its intensity if it overlaps with another dot.

Repeat the process above with the 100 leave votes layer except here we are going to use blue.  Just make sure you increase B(lue) to 255 rather than R(ed) when selecting the colour.

The map will now look like this, it works at  scales between 1:200,000 and 1:400,000.  You will need to have less dots if you want to zoom out further, or more or larger dots on a more zoomed in map.

Contains OS data © Crown copyright and database right (2017)

So you should now be able to make the distinction between the largely remain voting central London compared to the periphery where voting leave was more popular, particularly in the West.


The final thing you can do to your map is add labels to the London Boroughs so you can tell which is which. With such a busy map we are going to need buffers round the text.

  1. On the Layer Styling panel, change to LondonBoroughEURef then switch to the Labels tab: 
  2. Change to show labels for this layer.
  3. Change Label with to NAME.
  4. Choose a weightier font, I have used Franklin Gothic Demi.

Next we need to work on the formatting of the text so click on the format tab:




  1. Enter a space in the Wrap on Character field.
  2. Change the Alignment to Center.

The labels will now be better placed over the boroughs, though there won’t be enough room for them all unless you are more zoomed in.


The final steps are to add a mask or buffer to the text to make it stand out over the dots.

Click on the Buffer tab to start making changes:  

  1. Click the cross to Draw text buffer.
  2. I have left the Size as 1, but you may want to change this depending on your font.
  3. Set the buffer’s Transparency to something like 33% to allow some colour to show through.

That is the end of the instructions, you should have a map that looks similar to the one below:

Contains OS data © Crown copyright and database right (2017)

Creating 3D choropleth or prism map in QGIS 2.18

Contains OS data © Crown copyright and database right (2017)

It is possible to very quickly render any choropleth map you make in QGIS in 3D using the Qgis2threejs plugin. Essentially the plugin allows you to turn a numerical attribute as a “height” for your data. The results from the plugin are outputted as an html page which can be easily shared in a folder or placed on the web for people to view.

The Data


The Electoral Commission website contains a lot of data that can be used for making choropleth maps of all kinds. For this post I have used the EU Referendum results .CSV file:


If you are making choropleth maps of Great Britain then the best place to start with when looking for boundaries is the Ordnance Survey’s Boundary-Line Data:

The Method

I have used the data above to create a shapefile of London Boroughs with attributes that include the total number of votes, the number of votes to remain in the EU, and the number of votes to leave from the 2016 EU referendum. This was done using a table join based on the Area_Code from the result data CSV and the CODE in the Boundary-Line data for the London Boroughs.

The new file is called London Borough EU Ref and you can download a copy here:

I have also added in a Stamen Toner (Retina) basemap using the method described here: Adding web Basemaps in QGIS 2.18

Adding Qgis2threejs

To start creating your Prism Map you will need to add in the Qgis2threejs plugin using the Manage and Install Plugins interface:

Once installed you access the plugin via the Web menu in the top bar:

Setting up the data

Before we can get to work creating a 3D map we need to set up the data in the 2D map. In this example we are going to show the number of votes in the referendum for the London Boroughs as the 3D height, however we have the option to use the colour of the boroughs to show a second attribute. It is actually very useful to make the polygons different colours as it is then easier to interpret the map.

  1. Right-click on the London Borough EU Ref layer and select Open Attribute Table
  2. In the attribute table window click on the Field Calculator Button:

In the field calculator window we need to do the following:

  1. Check Create a new field
  2. Set the Output field name to be %_Remain
  3. Set the Output field type to be Decimal number (real)
  4. the Output field length can stay at 10 but set the Precision to be 2
  5. In the expression window create the following statement:

    ( “Vote_Remai” / “votes” ) * 100

  6. Click OK

You will now see the new column in the attribute table but you still need to save your change and turn off editing mode.

  1. Click on the Save Edits button:
  2. Click on the Edit Mode off button:

Styling the data

We can now apply a graduated colour scheme based on this new column.

  1. Press F7 on the keyboard to open the Layer Styling dock on the right side of the map
  2. Make sure you are editing the London Borough EU Ref layer at the top
  3. Change the Single Symbol option to Graduated
  4. Change the Column to %_Remain
  5. Change the Color ramp to RdBu (Red to Blue through White)
  6. Check the Invert option (this makes leave favouring areas blue and remain red, the standard colours adopted for the referendum results)
  7. Change the number of Classes to 7
  8. Set the Mode to be Equal Interval
  9. Click Classify
  10. Manually adjust the Values to 10% bands, starting at 20% votes to remain through to 80% votes to remain. Make sure that white represents 50%. If you double click in the the value column of the table in the Layer Styling dock it will open a window where you can edit each entry:
  11. Finally change the Layer Blending Mode to Multiply so that you can see the details of the base map through the colours with no nasty washed out effect you get with transparency. This effect works particularly well on the black and white basemap.

The resulting map is shown below, with the areas of the lowest votes to remain as the darkest blue, white represents 50%, and the darkest red in the areas with the most votes to remain:

Map data © OpenStreetMap contributors, Contains OS data © Crown copyright and database right (2017)

The Prism maps produced by Qgis2threejs show a flat plane with extruded blocks extending upwards. The flat plane will appear as it is in the map window. It can be good to have a little transparency on the extruded blocks and so you don’t want the colours you have just set interfering with this. However it can be useful to see the boundaries you are extruding upwards. To show these:

  • Right-click on the London Borough layer
  • Select Duplicate

You will end up with a copy of the layer called London Borough EU Ref copy

Style the new layer to show just the outlines:

  1. Set the style to be Single symbol, Simple fill
  2. Se the Fill to be Tranparent
  3. Set the Outline to be Black
  4. Increase the Outline width to 0.7 so it will show up a bit more clearly
Contains OS data © Crown copyright and database right (2017)

Preparing the map for conversion to 3D

You should now turn off the coloured London Boroughs layer and use the Zoom to Layer Extent to set up the map as show below:

Map data © OpenStreetMap contributors, Contains OS data © Crown copyright and database right (2017)

Setting up Qgis2threejs

You can now open the Qgis2threejs plugin from the Web menu:

There are a a whole raft of options to look at with this plugin as it can be used not only for Prism Maps but for accurate 3D landscape models too.

We’ll run through the changes needed to make a Prism Map, the rest of the parameters can be left as the default settings.

Well start at the top of the menu on the left:


The only thing to change here is the Background colour. The default is sky which works well for landscapes but I have set this to black which works better for the colours of this map.


This can be left as the defaults.


The only thing to change here is to scroll down and switch off the Build Sides option.

Additional DEM

This can be left as the defaults.


  1. First we need to set which polygon layer we are going to extrude up, check the box next to London Borough EU Votes.
  2. The main thing to change here is to set the Height value to be Votes
  3. multiplier to be 0.1. The values are set in map units but as there were so many votes this makes the Prisms too high. if you are dealing with low values over larger areas then you will need a high multiplier to see any effect.

The Results

So now you are ready to Run the plugin, I tend to leave the location to be the temp folder while I play around with the colours, zoom levels and height multipliers. Once you are happy then you can set your location and the plugin will create a folder there with all the information needed to create the html page:

Here is the result:

Map data © OpenStreetMap contributors, Contains OS data © Crown copyright and database right (2017)

Note that the website can take a while to generate and the more complicated the geometries of the polygons the longer it takes to render. Microsoft Edge and Internet Explorer can take a bit longer to display than FireFox and Chrome, but once loaded all browsers tend to run well.

One thing I have found is that the models look better when the polygons are simple. American States, which have a lot of straight lines, tend to work better than UK counties or constituencies. Here is the same data for London, but put into HexBins. I’ve added labels to help identify which hexagon represents which borough.

It is possible to edit the CSS to change things like the font and text size for the labels.

Map data © OpenStreetMap contributors

Here is a link to the actual model created:

London Remain Votes Prism Map

Creating a Proportional Symbol map in QGIS 2.18

Creating proportional symbol maps in QGIS is made very easy in QGIS with two main methods for making them. You can use basic Single Symbol style with the  Size Assistant in the Data Defined Override,  or you can use the Graduated style and choose Size as the method of gradation. Below is a set of instructions on how to use either method to create proportional point symbols for your map.

The Data

  • Download the 1:10 million populated places (Simple) Shapefile from Natural Earth:
  • Add in the Stamen Toner Lite WMS using either the OpenLayers or QuickMapServices plugins. If you haven’t done that before, here is a quick guide:

Method 1: Graduated Symbols

This method works best when you want to use all the points in your dataset. QGIS allows you to vary the size of the data point based on the values in attributes of the data.

  • First, open the live layer styling menu by pressing F7.

Make sure the top menu is set to the Natural Earth Point data then change Single symbol to be Graduated.

There are now a few new options to play with:

  • Change Column to be pop_max
  • Change Method to Size
  • Change “Size from” to 3 and “to” to 20
  • Click the Classify button to see how this looks.

The map will automatically update to look like the map show below, zoomed in to the UK and Northwest France:

You have flexibility to change the number of classes and how you divide the classes, Equal Interval, Quantiles, Natural Breaks etc. You can also manually edit the classes by double click in the values column in the table.

Method 2: Data Defined Override

If you want a little more control over how the data is displayed this method allows you to quickly change maximum and minimum values without having to set each level in between.

  • First, open the live layer styling menu by pressing F7
  • Make sure the top menu is set to the Natural Earth Point data
  • Click on the Data Driven Override button  on Size



  • Click on the Size Assistant option at the bottom of the box.

You will now be looking at the Size Assistant dialog. The options here are very similar to using the method described above, allowing you to select the field to base the size on and having control over size of the points.

  • Set the Field to be POP_MAX
  • Set the Scale method to be Radius
  • Change the “Size from” to be 3 and “to” to be 20

As you can see in the example above the symbols automatically scale from the smallest to the largest values in the field selected. However where this method has a big advantage over the previous one you can set the upper limit to be different. The points will now automatically scale to this value without you having to manually update each range. This can be very useful if you are viewing only a portion of the data.

In the area we zoomed to in the previous method the largest cities are London and Paris, both having a population of below 10,000,000

  • Change the “Values from” to be 0 and “to10,000,000

You can now see int he map below there is a bigger range of point sizes than the previous method for the area of the map.

Blend Modes

A little added tip is to use the blend modes on your symbology, so you can see the basemap through the shapes and reveal the detail on any overlapping symbols:

  • In the Layer Rendering section of the style tab change the Layer blending mode to be Multiply. This will allow you to see the basemap through the points
  • Change the Feature blending mode to be Multiply. This will allow you to see overlapping points within the point dataset.

The Result: