Tag Archives: JavaScript

Dataviz of the week, 5/7/17

This week we look at a clinical trial of treatments for tuberculosis, the PanaCEA MAMS-TB study. I’ve been involved with TB on and off since project-managing and statisticizing the original NICE guideline back in the day. I won’t go into detail on TB treatments but the trial compares various combinations of drugs, and there’s a new candidate drug called SQ109 in the mix. The paper is here (I hope it is not paywalled). You can see the Kaplan-Meier plot on page 44. Without going into detail, these are classic formats for clinical trials looking at time-to-event data. As time goes by, people either get recurrence of the disease or disappear out of the trial, and the numbers at risk go down. You want to be in a group whose curve descends less steeply.

But there are different ways of measuring and counting events, so the authors made an interactive web page showing these as a sensitivity analysis. Hooray!

Screen Shot 2017-06-23 at 12.55.33

It’s a pity Lancet paid such lip service to it, tucked away as a link in the margin of page 45. Boo!

I found the transitions in the table of patients at risk weird – I guess that’s the d3 transition deciding to move the numbers horizontally and it might be clearer to fade them out, remove them, then put them back from scratch. It’s also clear that Mike Bostock never had to deal with step functions in transition. But otherwise a really nice example of how trials can provide more layers of info. 

Leave a comment

Filed under healthcare, JavaScript, Visualization

Dataviz of the week: 1/3/17

Scribbly states” is not done with felt-tip pens but with some sweet use of D3 Javascript by Noah Veltman. I admire his attention to the little details, making it more human-like and commenting on the situations where it doesn’t work. Turns out if you follow the links, that the method came out of Apple, who patented it way back. Didn’t someone like @inconvergent have a script to make coffee rings? You could chuck that on top for extra authenticity.


Leave a comment

Filed under Uncategorized, Visualization

Visualizing HDI: a fine D3 exemplar

This interactive visualisation of Human Development Index values, by country and over time, was released last week.

For me, it follows in the mould of The State of Obesity, but is much more transparent in how it is constructed when you look at the source code. That makes it a good exemplar — in fact, perhaps the exemplar currently available — for introducing people to the possibility of making interactive dataviz for their research projects.

Oh for those early days of D3, when nobody was terribly fluent with it, and websites would have all the code right there, easy to read and learn from.

That transparency is important, not just for teaching about dataviz, but for the whole community making and innovating interactive data visualisation. Oh for those early days of D3, when nobody was terribly fluent with it, and websites would have all the code right there, easy to read and learn from. Now they are tucked away in obscure links upon links, uglified and mashed up with other JS libraries, familiar to the maker but (probably) not you. There are obvious commercial pressures to tucking the code away somewhere, and you can actually obtain software to obfuscate it deliberately. At the same time, having everything in one file, hard-coded for the task at hand, may be easy to learn from, but it isn’t good practice in any kind of coding culture, so if you want to be respected by your peers and land that next big job, you’d better tuck it all away in reusable super-flexible in-house libraries. And yet, the very availability of simple D3 code was what kick-started the current dataviz boom. Everyone could learn from everyone else really quickly because everything was open source. I don’t like to think that was a short-lived phase in the early part of the technology’s life cycle, but maybe it was…

Anyway, that’s enough wistful nostalgia (I learnt yesterday that I am the median age for British people, so I am trying not to sound like an old duffer). Here’s the things I don’t like about it:

  1. it requires a very wide screen; there’s no responsiveness (remember your audience may not work in a web design studio with a screen as big as their beard)
  2. life expectancy gets smoothed while the other variables don’t – just looks a bit odd
  3. why have colors for continents? Doesn’t it distract from the shading? Don’t we already know which one is which?
  4. Why give up on South Sudan, Somalia (which seems to be bunged together with Somaliland and Puntland in one big “hey it’s somewhere far away, they won’t notice” sort of way) and North Korea? Aren’t these countries’ estimates kind of important in the context, even if they are not very good? Do you really believe the Chinese estimates more than these just because they’re official?

But all in all, these are minor points and a nice amount of grit for the mill of students thinking about it. I commend it to you.

1 Comment

Filed under Visualization

Best dataviz of 2014

I expect everyone in the dataviz world would tell you this year was better than ever. It certainly seemed that way to me. I’m going to separate excellent visualisation for the purpose of communicating data from that for communicating methods.

In the first category, the minute I saw “How the Recession Reshaped the Economy, in 255 Charts“, it was so clearly head and shoulders above everything else that I could have started writing this post right then. It’s beautiful, intriguing and profoundly rich in information. And! quite unlike anything I’d seen in D3 before, or that’s to say it brings together a few hot trends, like scrolling to go through a deck, in exemplary style.


Next, the use of JavaScript as a powerful programming language to do all manner of clever things in your web browser. Last year I was impressed by Rasmus Bååth’s MCMC in JavaScript, allowing me to do Bayesian analyses on my cellphone. This year I went off to ICOTS in Flagstaff AZ and learnt about StatKey, a pedagogical collection of simulation / randomisation / bootstrap methods, but you can put your own data in so why not use them in earnest? It is entirely written in JavaScript, and you know what that means – it’s open source, so take it and adapt it, making sure to acknowledge the work of this remarkable stats dynasty!


So, happy holidays. If the good Lord spares me, I expect to enjoy even more amazing viz in 2015.

Leave a comment

Filed under JavaScript, Visualization

stata2leaflet v0.1 is released

Use Stata? Want to make an interactive online map with markers at various locations, colored according to some characteristic, with pop-up information when they’re clicked on? Easy. Head over to my website and download stata2leaflet. It’s in a kind of alpha testing version, so what I really want are your suggestions on making it even better. You’ll see my plans for v0.2 there too.

You have data like this:


You type this:

stata2leaflet mlat mlong mlab, mcolorvar(mcol) replace nocomments ///
title("Here's my new map") ///
caption("Here's some more details")

A file appears which looks like this inside:


And opens in your browser like this (static version because of WordPress.com restrictions – clickety click for the real McCoy):


Leave a comment

Filed under Stata, Visualization

NHS primary care boundaries (CCG and PCT in JSON format)

I always find it hard to track down shapefiles of primary care boundaries. It’s getting better but it’s still the case that what most people want – JSON files of CCGs and their historic counterparts PCTs – are not there, and who wants to waste time messing around trying to convert them? I spotted somebody’s JavaScript map of these primary care organisations today and took the chance to get under the hood and save the data files. The CCGs are here and the PCTs are here. I didn’t make them, so don’t come crying to me if something is not quite right – fix it.

Leave a comment

Filed under Visualization

A triumph of D3: see that uncertainty for yourself

This page is just out from the New York Times, showing trends in the USA jobs report and how they could easily be an artefact of sampling error. It’s a magnificent piece of data reporting: clear, punchy and helpfully demystifying. Sampling error is just what happens when you don’t have all the data, just a slice of it. You might be unlucky and get a wild over- or under-estimate. If you hear someone say that statistics is a tool to help you make decisions under conditions of uncertainty, or that statistics is a missing data problem, this is typically what they are getting at. Sampling error is not the only type of uncertainty, but it’s the one most amenable to mathematical probing, and often is the biggest one too.



As a keen D3 hanger-on, I have seen didactic examples about which randomise data like this, but it never occurred to me that it could actually be used to show uncertainty by simulation of the data (rather than some general fuzzy wobbling). I am very impressed with the clarity of the writing too.

Leave a comment

Filed under JavaScript, Visualization