1 | var w = 280, |
---|
2 | h = 280, |
---|
3 | m = [10, 0, 20, 35], // top right bottom left |
---|
4 | n = 10000; // number of samples to generate |
---|
5 | |
---|
6 | var chart = d3.chart.qq() |
---|
7 | .width(w) |
---|
8 | .height(h) |
---|
9 | .domain([-.1, 1.1]) |
---|
10 | .tickFormat(function(d) { return ~~(d * 100); }); |
---|
11 | |
---|
12 | var vis = d3.select("#chart") |
---|
13 | .append("svg:svg") |
---|
14 | .append("svg:g") |
---|
15 | .attr("transform", "translate(" + m[3] + "," + m[0] + ")"); |
---|
16 | |
---|
17 | d3.json("turkers.json", function(turkers) { |
---|
18 | var tm = science.stats.mean(turkers), |
---|
19 | td = Math.sqrt(science.stats.variance(turkers)), |
---|
20 | dd = [ |
---|
21 | [0.10306430789206111, 0.0036139086950272735, 0.30498647327844536], |
---|
22 | [0.5924252668569606, 0.0462763685758622, 0.4340870312025223], |
---|
23 | [0.9847627827855167, 2.352350767874714e-4, 0.2609264955190324] |
---|
24 | ]; |
---|
25 | |
---|
26 | var g = vis.selectAll("g") |
---|
27 | .data([{ |
---|
28 | x: d3.range(n).map(Math.random), |
---|
29 | y: turkers, |
---|
30 | label: "Uniform Distribution" |
---|
31 | }, { |
---|
32 | x: d3.range(n).map(normal1(tm, td)), |
---|
33 | y: turkers, |
---|
34 | label: "Gaussian (Normal) Distribution" |
---|
35 | }, { |
---|
36 | x: d3.range(n).map(normal3(dd)), |
---|
37 | y: turkers, |
---|
38 | label: "Mixture of 3 Gaussians" |
---|
39 | }]) |
---|
40 | .enter().append("svg:g") |
---|
41 | .attr("class", "qq") |
---|
42 | .attr("transform", function(d, i) { return "translate(" + (w + m[1] + m[3]) * i + ")"; }); |
---|
43 | |
---|
44 | g.append("svg:rect") |
---|
45 | .attr("class", "box") |
---|
46 | .attr("width", w) |
---|
47 | .attr("height", h); |
---|
48 | |
---|
49 | g.call(chart); |
---|
50 | |
---|
51 | g.append("svg:text") |
---|
52 | .attr("dy", "1.3em") |
---|
53 | .attr("dx", ".6em") |
---|
54 | .text(function(d) { return d.label; }); |
---|
55 | |
---|
56 | chart.duration(1000); |
---|
57 | |
---|
58 | window.transition = function() { |
---|
59 | g.map(randomize).call(chart); |
---|
60 | }; |
---|
61 | }); |
---|
62 | |
---|
63 | function randomize(d) { |
---|
64 | d.y = d3.range(n).map(Math.random); |
---|
65 | return d; |
---|
66 | } |
---|