All examples By author By category About

seemantk

Bar Chart I: Causes of Death in Zambia

Visualizing causes of death in Zambia: I

From the 2015 Living Conditions Survey

Introduction

In August, I presented a workshop called d3.fundamentals() at BongoHive in Lusaka, Zambia. The Zambian Government's Central Statistical Office ran a survey in 2015, to determine the Living Conditions of people throughout the country. They graciously provided anonymized datasets for us to use during the workshop.

Chinyanta Mwenya, a Zambian hacker, collaborated with me to prepare the datasets for the workshop. Chinyanta cleaned the dataset and ran statistical analysis using both Excel and R. We took some time to find a smallish dataset that was easy to understand. We settled on the unfortunately morbid Causes of Death dataset.

For the workshop I assumed a minimal knowledge of HTML and CSS, and no knowledge of Javascript (let alone any knowledge of d3). So, the workshop turned out to be, essentially From Zero to Bar Chart with d3.

Rather than a bunch of pre-done, canned examples, I opted to live-code my way through the agenda. The journey went as follows:

This bl.ock is the result of that demo. It is presented here with minimal cleanup (spaces/indentations and moving variable declarations near the top).

The goal with this first visualization was to introduce d3 concepts while live-coding. So we built a bar chart showing the number of people who died from each cause listed.

Fundamentals

  1. The <style> section contains styling for the axis:
  1. We use d3.csv() to read in the data file:
  1. We use d3.nest() to group the array of objects by CAUSE
  1. We use scales to map from data space to screen space.
  1. We draw an SVG <rect> for each bar in the bar chart.
  1. We label the bar by using the axis labels of a d3.svg.axis()

Analysis

This is a great start to visualizing this dataset. We can easily tell the relative seriousness of each cause of death. We can see that FEVER/MALARIA kills about 2 times more people as the next cause of death (OTHER, or miscellaneous, causes).

Improvements

It's a basic chart that gives us a basic insight into the dataset. By making some small changes, we can vastly improve our insight.

Next, let's make the chart easier to read.