<commit_before>---
title: Complete choropleth dev. workflow in R (Part 1)
date: 2015-04-21
layout: post
category: GIS
tags: gis leaflet choropleth datakind
year: 2015
published: true
summary: Part 1 of Complete choropleth dev. workflow in R
---

I attended the last DataKind Data Dive in Leeds.

![datakind](/images/DataKindUK.png)

Once more, we had to confront the issue of producing attractive choropleths from shapefiles, in a short time.

I thought to document the entire complete workflow here, as usually is a struggle to remember how to go about it.

This workflow is the result of hours of experiments, consulting many blogs and stackoverflow posts.  I am grateful for all the help received but I am unable to recognise every contribution.  Perhaps the best way to say thank you is to give back to the community in the form of this post.

#### The process

The process is fairly simple, but includes many different steps and many R libraries, hence it is important to know what you are doing (or follow the steps precisely!).

The steps are

1. Get shapefiles
2. Get the shapefiles of the area of interest
3. Select the shapefile (and re-project if necessary)
4. Simplify the shapefile and save it to geojson
5. Intro to choropleth libraries
6. Prepare the data
7. The leaflet library
8. The rdatamaps library
9. Lesson learned

First step of course is to get adequate shapefiles.

#### Get shapefiles

The easiest thing, especially if you need to build a choropleth with census data or generally open data, is to get the shapefile from some official source. In the UK the [ONS Open Geography Portal](https://geoportal.statistics.gov.uk/geoportal/catalog/main/home.page) offers a great service (I understand developed also with the help of the Ordnance Survey).
<commit_msg>repos image<commit_after>---
title: Complete choropleth dev. workflow in R (Part 1)
date: 2015-04-21
layout: post
category: GIS
tags: gis leaflet choropleth datakind
year: 2015
published: true
summary: Part 1 of Complete choropleth dev. workflow in R
---
![datakind](/images/DataKindUK.png)

I attended the last DataKind Data Dive in Leeds.

Once more, we had to confront the issue of producing attractive choropleths from shapefiles, in a short time.

I thought to document the entire complete workflow here, as usually is a struggle to remember how to go about it.

This workflow is the result of hours of experiments, consulting many blogs and stackoverflow posts.  I am grateful for all the help received but I am unable to recognise every contribution.  Perhaps the best way to say thank you is to give back to the community in the form of this post.

#### The process

The process is fairly simple, but includes many different steps and many R libraries, hence it is important to know what you are doing (or follow the steps precisely!).

The steps are

1. Get shapefiles
2. Get the shapefiles of the area of interest
3. Select the shapefile (and re-project if necessary)
4. Simplify the shapefile and save it to geojson
5. Intro to choropleth libraries
6. Prepare the data
7. The leaflet library
8. The rdatamaps library
9. Lesson learned

First step of course is to get adequate shapefiles.

#### Get shapefiles

The easiest thing, especially if you need to build a choropleth with census data or generally open data, is to get the shapefile from some official source. In the UK the [ONS Open Geography Portal](https://geoportal.statistics.gov.uk/geoportal/catalog/main/home.page) offers a great service (I understand developed also with the help of the Ordnance Survey).

{'fraction_non_alphanumeric': 0.04995790064552343, 'fraction_numerical': 0.012910468706146505, 'mean_word_length': 4.233480176211454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1994813', 'n_tokens_mistral': 1020, 'n_tokens_neox': 928, 'n_words': 561}