Visualize Data with Choropleth Maps

Chinmay Gaikwad
ChiGa
Published in
3 min readJul 8, 2020

Create an interactive map to visualize the COVID-19 pandemic

Are you overwhelmed by the continuous newscast of Coronavirus?

Like any other fast-spreading contagion, COVID-19 also comes with an exponentially rising barrage of information continually throwing at us through the news and social media, stoking stress and anxiety. But what if we utilise this information to bring out some useful insights?

Photo by Jay Heike on Unsplash

Choropleth map

A Choropleth map is a type of thematic map in which regions of a map are shaded in proportion to the amount of the statistical data being represented, such as population, temperature or it could be the number of COVID-19 cases also. A Choropleth map enables us a robust way to visualize how a certain entity varies across a geographic area or it manifests the level of variability within a region.

To create a Choropleth map of a region, we need a GeoJSON file of that region. It is a geospatial data interchange format based on JavaScript Object Notation (JSON) that determines the areas and boundaries of a state, district or country. GeoJSON is used for encoding a range of geographic data structures.

GeoJSON supports Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon geometry types. Geometric objects with extra characteristics are Feature objects. Collection of features are enclosed by FeatureCollection objects.

A typical format of GeoJSON is as follows:

{  
"type": "Features",
"geometry": {
"type": "Point",
"coordinates": [93.715553, 7.207223]
},
"properties": {
"name": "Andaman and Nicobar"
}
}

For more details on GeoJSON, refer to the documentation.

In our case, since we are aiming to generate a map of confirmed COVID-19 cases across Indian states, we will need a GeoJSON file which describes India’s internal and external boundaries.

In order to proceed, a few more important parameters required are:

  1. geo_data, which is a GeoJSON file.
  2. data, which is a dataframe containing the data.
  3. columns, which describes the columns in the dataframe which will be employed to generate the Choropleth map.
  4. key_on, It is a key or variable in the GeoJSON file that has the name of the target variable. To determine that, we need to open the GeoJSON file using a text editor and note the name of the key or variable that contains the name of the country, state or district.

An important point to note here is that key_on is case_sensitive, so you will have to enter the exact variable name as it appears in the GeoJSON file

Now that we have all the required files and data, Let’s get started!

Firstly, we will import python libraries and install Folium to generate maps. If you’re new to Folium here’s a basic guide to go!

Now, load the dataset into a pandas dataframe.

Select only required columns and scrap out unnecessary fields

Display the final dataframe

Then, load the GeoJSON file and set the threshold scale.

It’s important to define the threshold scale otherwise the scale on the legend will start with a negative value.

Finally, Let’s plot the data on the map by using Folium’s Choropleth feature. Observe how the parameters have been assigned with the values from dataframe and GeoJSON file.

And voila, you are ready to go!

Confirmed COVID-19 cases across states of India

Create interactive Choropleth maps using Python and Folium, come back here and tell us about compelling use cases of Choropleth maps. I bet you’ll have something to say!

--

--