Eurostat gives a lot of statistical data, most of the times georeferred. This makes easy to create nive maps telling stories about any topic you may be interested in.
Unfortunately, I didn’t find an easy way to do that using D3js, so I wrote a post some time ago on how to do it. The idea worked, but I think that it can be done really easily, without python scripts, just by downloading Excel sheets and exporting to CSV. Also, with the new d3-composite-projections version, a convenient projection has been added to show the island and terrotories away from Europe, but that appear at the Eurostat data.
The idea is creating the maps as Eurostat does:
You can see the working example at bl.ocks.org, and it looks like this:
Downloading some sample data
To create a map, you will need two data sources:
- The regions where the data belongs. The regions are coded in a system called NUTS (Nomenclature of territorial units for statistics)
- The data you want to represent at each region, such as Greenhouse gas emisions, murders, etc
Getting the regions and using them in TopoJSON format is not very straigth forward, so I did it for you.
The files are at [this gist][https://gist.github.com/rveciana/5919944], with the names nuts0.json, nuts1.json, etc. You can use rawgit to get the files without downloading them. To get the nuts3 topojson:
If you want to know how to generate these TopoJSONs, you can check the next post
Getting the information data
To get the data, you have first to decide which data to use. In my case, I have chosen to map the amount of people at risk of poverty or social exclusion. To do it, from the main page, I have done:
Population and Social conditions -> Income and living conditions -> Main Tables -> People at risk of poverty or social exclusion by NUTS 2 regions.
From there, choose Tables, maps and graphs interface:
Choose the More data in the source dataset button:
Then, the GEO + button:
Once there, ask to get not just the region names, but the labels too, so the topoJSON codes can be used. Don’t forget to click the update button:
Now you can click the download button and ask to have the labels in a separate column from the name (or doing it yourself will be a mess, believe me):
Oce the excel file is generated, export it to CSV. In our case, two tables are generated. I have chosen the first one percentage of total population, and remove the other parts.
Why not generating CSV files directly if there is an option? Because it will generate a row for each year and region, making things much more difficult.
Creating the map
To create the map, I’ve done it as usual, but loading a the csv with the variable data. This way, just by changing the csv, creating new maps is very easy. The working example is at bl.ocks.org.
Some things deserve a little explanation.
Creating the color scale:
I have used the colorbrewer2 library, which gives many color scales already made. You just have to choose how many colors to use (9 in the example) and the scale name (OrRd). Choosing one is really simple. Just go to the library page and play with the examples until you have the codes.
The domain indicates the maximum and minumum values for the scale. Since no country has values lower than 10 or higher than 60, I forced these limits.
Choosing the color to paint the region:
I took this data because it’s not perfect. Some data is given by NUTS2 and other by NUTS1. This is, some is given by country and other by quite large regions.
- data has all the csv data as a structure. When choosing the key d.id, the data for the current region should be used.
- The regions with NUTS1 data won’t work, since the code is for the whole country, not for the region. Fortunately, the NUTS2 codes include the NUTS1 code. This is UK12 belongs to UK. Thats why I used the conditional. If no value is found, we try with the first two characters, and the NUTS1 code may match then.
- In some cases, the region is not found, since it’s not in the CSV file. A white color is then returned.
To show a small tooltip, a similar solution is used.
The whole code, running at bl.ocks.org is this one: