natural breaks for coloring

1,123 views
Skip to first unread message

Drew Dara-Abrams

unread,
Oct 6, 2011, 5:36:30 PM10/6/11
to d3-js

Mike Bostock

unread,
Oct 6, 2011, 6:21:02 PM10/6/11
to d3...@googlegroups.com
> Has anyone used d3 to compute natural breaks for coloring?

I have not, but keep me posted if you do. I love ColorBrewer for thematic maps:

http://colorbrewer2.org/

There are CSS and JS files for ColorBrewer included in the git
repository. If you end up rolling your own color scales, Jeff Heer has
also implemented L*a*b* color space support for D3 (see his fork), and
there are other JavaScript color space implementations available.

Mike

Drew Dara-Abrams

unread,
Oct 19, 2011, 2:26:26 PM10/19/11
to d3...@googlegroups.com
Mike,

Yeah, I've had good luck with ColorBrewer. I had forgotten about the CSS/JS files in the repo; will have to make use of those.

Here's the Python code I'm using on the server side to do the natural breaks classification: https://gist.github.com/1299198 Sometime soon I'll probably need to use this on the client side as well, so I'll rewrite it as JavaScript.

Do you see a place for this in d3?

Drew

Mike Bostock

unread,
Oct 19, 2011, 4:47:15 PM10/19/11
to d3...@googlegroups.com
Ah, interesting. I thought you were describing natural breaks in color
space, rather than natural breaks in data space (which you then map to
existing color scales). I typically use either a quantize or quantile
scale for this purpose, which have well-defined behaviors. The natural
break approach relies more heavily on having a legend for
understanding, but I could still see it as being useful.

It'd be great to have an example of how to do this in JavaScript. If
it's something that is commonly-needed, we could figure out a place to
put it in D3, perhaps as a scale.

Mike

Drew Dara-Abrams

unread,
Oct 20, 2011, 3:03:44 AM10/20/11
to d3-js
Yeah, I should have mentioned that it's a scale in data space. Useful
when you have "clumpy" data that don't display well in quantiles.

Down the line when I have JS code, I'll post again...

Drew

Fiachra O Donoghue

unread,
Oct 20, 2011, 10:12:13 PM10/20/11
to d3...@googlegroups.com
There's a project that implements Jenks algorithm in JavaScript at https://github.com/simogeo/geostats. This gist: https://gist.github.com/1302938 is a function I adapted (mostly just copied) from D3's d3.scale.quantile to accept an additional argument that names a function from the simogeo/geostats library and returns the class breaks generated by that classsification algorithm. 

For Jenks you'd call it like this:  
var classes = d3.scale.flexiclass('getJenks').domain([domain]).range([range]);
It also has equal intervals ('getEqInterval') and quantiles('getQuantile').

Regards
Fiachra

Marjorie Roswell

unread,
Dec 8, 2013, 4:32:37 PM12/8/13
to d3...@googlegroups.com
Here's another implementation:
https://gist.github.com/tmcw/4969184

Would love to see this (along with associated legend) built into D3.

Michael Neutze

unread,
Dec 11, 2013, 4:11:59 PM12/11/13
to d3...@googlegroups.com
I second Marjorie's proposal.
Tom MacWright's (of mapbox fame) Jenks implementation has been proven easy to implement, provides great results and would make a valuable addition to d3js.

Mike, do prefer this as a feature request on github?

Tom went to great length studying the original research of Jenks instead of rewriting that age-old fortran implementation, see here

Daniele Pennati

unread,
May 13, 2014, 5:02:34 PM5/13/14
to d3...@googlegroups.com
Hello,
I've implemented the simple_statistics jenks scale in a d3 map.
but I have an issue... If I set the same number of classes for the scale in d3, in qGis or in ArchMap I got 3 really different results.
There isn't a common algorithm to determine the natural brakes? Do you have any idea why I got different brakes with the same dataset?

thanks
Daniele
Reply all
Reply to author
Forward
0 new messages