Erik Cunningham
@trinary
A place for hands on learning about visualization.
I'm focused on D3, but there are lots of other tools out there.
You probably saw the note I sent out about getting GitHub going on your computer. I want this to be a place that we get into the details Whenever possible, presentations should have a way for the group to be hands-on.William Playfair, 1758
We've been doing this for a long time, and in its current form for 250ish yearsThe largest known systems in the human brain process visual information.
We see trends, patterns, and outliers in images far faster than in raw data.
It also brings overfitting, bias, and other distortions.
Because done poorly, data visualization at best obscures the truth, and at worst lies about it.
Count the dimensions shown here:
Charles Minard, 1868
Considered by many to be the best visualization ever made.Hundreds of pieces of data in five dimensions, distilled into a single, understandable image.
"The great growth of statistical research in our times has made felt the need to record the results in forms less dry, more useful, and able to be explored more rapidly than numbers alone."
Minard
The Bay Area D3 group decided to do some analysis.
Community D3 group who wanted to get some analysis and answers on the strike issueData Driven Documents
Created by Mike Bostock
Builds off of work in Protovis at the Stanford Vis Group
Maps data to DOM (HTML, SVG)
Limited support for Canvas rendering targets (geo projections)
Initial release in 2011. JQuery was released in 2006. Backbone 0.1.0 2010.389 API functions in 47 objects.
Mike Bostock's examples page has 681 curated examples.
There are lots of tricks and non-obvious patterns, a common complaint is that the learning curve is far too steep.
No presets, no wizards.
It is a tool that allows you to create the visualization you want, rather than pick one from a menu.
Limited support for IE, especially versions before 10
Workarounds: compound lines, draw orderingGiven an array of data:
[0,1,2]
Bind it to an existing set of elements:
<div></div> <div></div> <div></div>
Like this:
d3.selectAll("div").data([0,1,2])
Given a data binding
d3.select("body").selectAll("div").data([0,1,2])
Tell D3 what to do when there is no corresponding document element for a data element:
<body></body>
d3.select("body").selectAll("div").data([0,1,2]).enter().append("div");
"Inside the body tag, bind each element of [0,1,2] to a div, creating it inside body if it doesn't exist."
Given an existing data binding, with elements created via enter()
s = d3.select("body").selectAll("div").data([0,1,2]); s.enter().append("div");
Tell D3 what to do when there's no data to be bound to an element:
s.exit().remove();
"If there's no data for an existing element, remove() it."
When setting attributes or styles on bound elements, you can supply a callback.
myData = [{ size: 10}, {size: 2}]; ... mySelection.attr("r", function(d,i) { return d.size; });
The bound data and its index in the data array get passed in.
The return value is gets set as the attribute value.
Tributary is a live-coding environment for D3.
http://tributary.io/inlet/7049427
The x positions of the circles are determined by the value of each element in data
Yeah, you're right. Let's take a look at something more relevant.
A bar chart!
SVG uses a (0,0) point at the upper left corner.
For our bar chart to look right, we need to specify the y and height values with this in mind.
Let's take a look: http://tributary.io/inlet/7112787
These techniques are used with d3 primitives like:
They result in the beautiful, interactive vector displays you see in examples. The way the API gets used is more sophisticated, but these fundamentals are how they are implemented.
Here's what a bar chart looks like using more of D3's functionality.
Edit the working bar chart example:
If you already know how to do this, help the people near you.