Transcript
Page 1: The anatomy of an infographic

The anatomy ofan infographic

/ Luca Mearelli @lmea

Page 2: The anatomy of an infographic

The Wealth & Health of Nation

300 400 1,000 2,000 3,000 4,000 10,000 20,000 30,000 40,000 100,00010

20

30

40

50

60

70

80

income per capita, inflation-adjusted (dollars)

life

expe

ctan

cy (y

ears

)

1800Source:  ,  , Mike Bostock Tom Carden Gapminder

Page 3: The anatomy of an infographic

Visualization =

Data + RepresentationThe end target is to extract meaningful informations from the

raw data.

Page 4: The anatomy of an infographic

Javascript &

Web technologiesAre the ideal platform to build visualizations: easy to tinker

with, powerful, accessible.

Page 5: The anatomy of an infographic

D3jsD3 is a tool to link data to elements and manipulate them.

http://d3js.org

Page 6: The anatomy of an infographic

Chris Viau on D3 vs JQuery

D3 is not an SVG layer, not a compatibility layerand especially not an abstraction layer.

It's a set of tools on top of web technologies tobind data to DOM elements. '

Page 7: The anatomy of an infographic

http://iside.rm.ingv.it/iside/standard/index.jsp

Page 8: The anatomy of an infographic

DataTime,Lat,Lon,Depth,Mag,Source,2013-05-09 14:30:35.000,43.451,12.310,6.7,1.3,SISBAS,2013-05-09 14:15:25.000,43.452,12.308,6.3,0.8,SISBAS,

quakes = [[ "2013-05-08 11:50:14.000", 43.450, 12.298, 9.6, 3.0 ], [ "2013-05-08 04:29:05.000", 43.452, 12.304, 10.1, 3.3 ]]

Page 9: The anatomy of an infographic

Lets make a barchart (or two) http://tributary.io/inlet/5567235

http://tributary.io/inlet/5567278

Page 10: The anatomy of an infographic

Margin conventions

http://bl.ocks.org/mbostock/3019563

Page 11: The anatomy of an infographic

Selectionsvar svg = d3.select('svg');svg.attr({ 'width': width + margin.left + margin.right, 'height': height + margin.top + margin.bottom})

var barsGroups = graph.selectAll('g')

http://bost.ocks.org/mike/selection/

Page 12: The anatomy of an infographic

Binding datavar text = svg.selectAll("rect") .data(quakes);

Page 13: The anatomy of an infographic

The general update pattern// Join new data with old elements, if any.var text = svg.selectAll("text").data(quakes);

// Update old elements as needed.text.attr("class", "update");

// Create new elements as needed.text.enter().append("text") .attr("class", "enter") .attr("x", function(d, i) { return i * 32; })

// Appending to the enter selection expands // the update selectiontext.text(function(d) { return d[4]; });

// Remove old elements as needed.text.exit().remove();

http://bl.ocks.org/mbostock/3808218

Page 14: The anatomy of an infographic

ScalesDomain → Range

var magScale = d3.scale.linear() .domain([2.0, 8.0]) .range([0, 225]);

https://github.com/mbostock/d3/wiki/Scales

Page 15: The anatomy of an infographic

Functions everywherevar magExtent = d3.extent(quakes, function (d) { return d[4]; });

selection .append('rect') .attr({ 'height': function(d,i){ return magScale(d[4]); }})

selection.call(aFunction)

Page 16: The anatomy of an infographic

Call chainingbarsGroups .append('text') .text(function(d,i) { return String(d[4]);}) .attr('y', -4) .attr("dx", 5) .attr("text-anchor", "middle") .attr('font-size', 10)

Page 17: The anatomy of an infographic

More charts (animated!) http://tributary.io/inlet/5567290

http://tributary.io/inlet/5567292

Page 18: The anatomy of an infographic

Axesvar yAxis = d3.svg.axis() .scale(magScale.range([300,30])) .orient('left') .ticks(5) .tickValues([3.0, 3.2, 3.4, 3.6, 3.8]) .tickSize(-width, 1, 1) .tickPadding(8);

graph.append('g') .call(yAxis)

https://github.com/mbostock/d3/wiki/SVG-Axes

Page 19: The anatomy of an infographic

Object constancygraph.selectAll('g') .data(dd, function(d){ return d.Time })

Page 20: The anatomy of an infographic

A dynamic barcharthttp://tributary.io/inlet/5567329

Page 21: The anatomy of an infographic

TransitionsbarsGroups .transition() .duration(2000) .ease('cubic') .attr("transform", function(d,i){ x = timeScale(tf.parse(d[0])); y = 234-magScale(d[4]); return "translate(" + x + "," + y + ")"; })

http://bost.ocks.org/mike/transition/

Page 22: The anatomy of an infographic

A simple scatterplothttp://tributary.io/inlet/5567399

Page 23: The anatomy of an infographic

Zooming scatterplothttp://tributary.io/inlet/5567408

Page 24: The anatomy of an infographic

Zoomingvar zoom = d3.behavior.zoom() .x(timeScale) .on("zoom", zoomed);

Page 25: The anatomy of an infographic

Lets make a map http://tributary.io/inlet/5567414

http://tributary.io/inlet/5567524

Page 26: The anatomy of an infographic

Projections & geodatavar projection = d3.geo.mercator() .scale(2100) .translate([-122,2000])

var path = d3.geo.path() .projection(projection);

svg.selectAll("path") .data(regions) .enter() .append('path') .attr('d', path)

Page 27: The anatomy of an infographic

Loading datad3.json("/static/data/cartography/reg2011.json", function(error, data) {})

queue() .defer("/static/data/cartography/reg2011.json") .defer("/static/data/quakes.csv") .await(function(error, reg2011, quakes) { ... });

Page 28: The anatomy of an infographic

A more complex maphttp://tributary.io/inlet/5567533

Page 29: The anatomy of an infographic

Assorted TipsGroup thingsQueue.js:Crossfilter:Topojson:Use rapid prototyping tools (e.g. Tributary: )

https://github.com/mbostock/queuehttp://square.github.io/crossfilter/

https://github.com/mbostock/topojsonhttp://tributary.io

Page 30: The anatomy of an infographic

Thanks!Luca Mearelli / @lmea


Top Related