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).
By John Paull and Benjamin Hennig (http://orgprints.org/30187/) [CC BY 3.0 (http://creativecommons.org/licenses/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:
Search for Cartogram, once installed you should see it in your list of plugins:
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 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:
A very simple interface opens where you select the data you want and the attribute you want to scale it by:
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.
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:
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:
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:
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.
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:
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:
Make sure the Create a new field option is selected and enter the name 100 Leave Votes.
Make sure the Output field type is set to Whole number (interger) and the Output field length can be left at the default 10.
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.
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
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:
Although we are making a density map we are going to use the Points countSampling strategy. This will assign the number of points in the Number field to each polygon.
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!
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.
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.
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.
Use the drop down menu at the top of the Layer Styling panel to change the layer to 100 Remain Votes.
Click Simple Marker to reveal more options.
Set the Size to be 0.6 (Millimeters).
Set the Outline Style to be No Pen.
Set the Layer lending mode to be Multiply
Set the Feature blending mode to be Multiply
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:
Set R(ed) to be 255 (Full) and G(reen) and B(lue) to be 0.
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.
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.
On the Layer Styling panel, change to LondonBoroughEURef then switch to the Labels tab:
Change to show labels for this layer.
Change Label with to NAME.
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:
Enter a space in the Wrap on Character field.
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:
Click the cross to Draw text buffer.
I have left the Size as 1, but you may want to change this depending on your font.
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:
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 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:
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.
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.
Right-click on the London Borough EU Ref layer and select Open Attribute Table
In the attribute table window click on the Field Calculator Button:
In the field calculator window we need to do the following:
Check Create a new field
Set the Output field name to be %_Remain
Set the Output field type to be Decimal number (real)
the Output field length can stay at 10 but set the Precision to be 2
In the expression window create the following statement:
( “Vote_Remai” / “votes” ) * 100
You will now see the new column in the attribute table but you still need to save your change and turn off editing mode.
Click on the Save Edits button:
Click on the Edit Mode off button:
Styling the data
We can now apply a graduated colour scheme based on this new column.
Press F7 on the keyboard to open the Layer Styling dock on the right side of the map
Make sure you are editing the London Borough EU Ref layer at the top
Change the Single Symbol option to Graduated
Change the Column to %_Remain
Change the Color ramp to RdBu (Red to Blue through White)
Check the Invert option (this makes leave favouring areas blue and remain red, the standard colours adopted for the referendum results)
Change the number of Classes to 7
Set the Mode to be Equal Interval
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:
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:
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
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:
Set the style to be Single symbol, Simple fill
Se the Fill to be Tranparent
Set the Outline to be Black
Increase the Outline width to 0.7 so it will show up a bit more clearly
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:
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.
This can be left as the defaults.
First we need to set which polygon layer we are going to extrude up, check the box next to London Borough EU Votes.
The main thing to change here is to set the Height value to be Votes
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.
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:
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.
This is a very quick guide on adding web basemaps to QGIS 2.18. I’ve created it as it is often the first step in creating a new map.
The easiest way to add in a basemap from the web is to use one of two plugins to add in the data for you. The two best plugins I have found for doing this are the OpenLayers and QuickMapServices.
The OpenLayers plugin from Sourcepole allows you to add in maps layers like OpenStreetMap (Including brilliant styles from Thunderforest and Stamen), Bing, Google and Apple.
The layers area accessed via the Web menu in the top bar of QGIS
Use the drop down menus to choose a layer and then simply click on it to add it to your map.
QuickMapServices from NextGIS has a huge number of services available (790 at the last count, but not all of them are active ) . You can select a few of these using the same select and click method as the OpenLayers plugin, but as there are so many to choose from the search interface is a much needed facility:
Once selected from the menu the Search QMS window opens on the right side of the map:
Once you have found a service you want, just click Add. There is a full cataloge on the NextGIS website here: https://qms.nextgis.com/
Along with the regular Web Mapping Services (WMS) you can also get Tile Map Services (TMS), Web Feature Services (WFS) and GeoJSON data piped straight into your map.
I have found layers added via QMS to be much quicker than those added using OpenLayers, however some layers are a little less stable and sometimes all layers from the plugin refuse to work without restarting QGIS.
OpenLayers is steady and stable and can usually be relied upon to provide you with maps. QMS has a much larger range of maps available and serves them up lightning fast, great for backdrop maps when making animated maps with the TimeManager plugin.
Basically, have them both installed and use whichever suits your project!
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.
Download the 1:10 million populated places (Simple) Shapefile from Natural Earth:
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 “to” 10,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.
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.