-
Notifications
You must be signed in to change notification settings - Fork 0
/
histogram_r.html
96 lines (77 loc) · 9.6 KB
/
histogram_r.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.bar {
fill: steelblue;
}
.bar:hover {
fill: brown;
}
.axis {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.x.axis path {
display: none;
}
</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .0);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var data = [{"color":0,"frequency":157576},{"color":1,"frequency":160915},{"color":2,"frequency":94381},{"color":3,"frequency":46607},{"color":4,"frequency":27188},{"color":5,"frequency":21431},{"color":6,"frequency":20989},{"color":7,"frequency":17289},{"color":8,"frequency":16190},{"color":9,"frequency":16039},{"color":10,"frequency":15717},{"color":11,"frequency":15099},{"color":12,"frequency":16695},{"color":13,"frequency":14652},{"color":14,"frequency":15911},{"color":15,"frequency":17015},{"color":16,"frequency":16165},{"color":17,"frequency":17085},{"color":18,"frequency":18501},{"color":19,"frequency":18261},{"color":20,"frequency":19275},{"color":21,"frequency":20437},{"color":22,"frequency":20498},{"color":23,"frequency":22321},{"color":24,"frequency":22810},{"color":25,"frequency":22048},{"color":26,"frequency":22337},{"color":27,"frequency":21688},{"color":28,"frequency":21571},{"color":29,"frequency":19074},{"color":30,"frequency":17107},{"color":31,"frequency":15776},{"color":32,"frequency":14948},{"color":33,"frequency":14814},{"color":34,"frequency":14133},{"color":35,"frequency":12942},{"color":36,"frequency":12952},{"color":37,"frequency":12794},{"color":38,"frequency":12165},{"color":39,"frequency":12116},{"color":40,"frequency":11952},{"color":41,"frequency":11597},{"color":42,"frequency":11533},{"color":43,"frequency":11702},{"color":44,"frequency":11429},{"color":45,"frequency":11188},{"color":46,"frequency":11246},{"color":47,"frequency":9634},{"color":48,"frequency":8620},{"color":49,"frequency":7613},{"color":50,"frequency":6899},{"color":51,"frequency":6361},{"color":52,"frequency":6063},{"color":53,"frequency":5592},{"color":54,"frequency":5173},{"color":55,"frequency":5121},{"color":56,"frequency":4999},{"color":57,"frequency":4681},{"color":58,"frequency":4477},{"color":59,"frequency":4158},{"color":60,"frequency":4073},{"color":61,"frequency":3946},{"color":62,"frequency":3740},{"color":63,"frequency":3577},{"color":64,"frequency":3314},{"color":65,"frequency":3145},{"color":66,"frequency":3060},{"color":67,"frequency":2860},{"color":68,"frequency":2785},{"color":69,"frequency":2586},{"color":70,"frequency":2518},{"color":71,"frequency":2463},{"color":72,"frequency":2346},{"color":73,"frequency":2279},{"color":74,"frequency":2143},{"color":75,"frequency":2112},{"color":76,"frequency":2026},{"color":77,"frequency":1980},{"color":78,"frequency":1981},{"color":79,"frequency":2041},{"color":80,"frequency":1928},{"color":81,"frequency":1880},{"color":82,"frequency":1835},{"color":83,"frequency":1752},{"color":84,"frequency":1842},{"color":85,"frequency":1817},{"color":86,"frequency":1769},{"color":87,"frequency":1828},{"color":88,"frequency":1768},{"color":89,"frequency":1704},{"color":90,"frequency":1765},{"color":91,"frequency":1732},{"color":92,"frequency":1730},{"color":93,"frequency":1700},{"color":94,"frequency":1761},{"color":95,"frequency":1624},{"color":96,"frequency":1623},{"color":97,"frequency":1597},{"color":98,"frequency":1571},{"color":99,"frequency":1557},{"color":100,"frequency":1534},{"color":101,"frequency":1551},{"color":102,"frequency":1542},{"color":103,"frequency":1523},{"color":104,"frequency":1536},{"color":105,"frequency":1514},{"color":106,"frequency":1436},{"color":107,"frequency":1543},{"color":108,"frequency":1456},{"color":109,"frequency":1529},{"color":110,"frequency":1415},{"color":111,"frequency":1472},{"color":112,"frequency":1449},{"color":113,"frequency":1458},{"color":114,"frequency":1417},{"color":115,"frequency":1364},{"color":116,"frequency":1407},{"color":117,"frequency":1382},{"color":118,"frequency":1468},{"color":119,"frequency":1448},{"color":120,"frequency":1475},{"color":121,"frequency":1470},{"color":122,"frequency":1476},{"color":123,"frequency":1507},{"color":124,"frequency":1582},{"color":125,"frequency":1525},{"color":126,"frequency":1617},{"color":127,"frequency":1561},{"color":128,"frequency":1621},{"color":129,"frequency":1653},{"color":130,"frequency":1764},{"color":131,"frequency":1821},{"color":132,"frequency":1804},{"color":133,"frequency":1801},{"color":134,"frequency":1968},{"color":135,"frequency":1956},{"color":136,"frequency":2017},{"color":137,"frequency":2081},{"color":138,"frequency":2066},{"color":139,"frequency":2068},{"color":140,"frequency":2153},{"color":141,"frequency":2240},{"color":142,"frequency":2309},{"color":143,"frequency":2269},{"color":144,"frequency":2282},{"color":145,"frequency":2337},{"color":146,"frequency":2381},{"color":147,"frequency":2312},{"color":148,"frequency":2359},{"color":149,"frequency":2292},{"color":150,"frequency":2355},{"color":151,"frequency":2391},{"color":152,"frequency":2383},{"color":153,"frequency":2377},{"color":154,"frequency":2200},{"color":155,"frequency":2335},{"color":156,"frequency":2241},{"color":157,"frequency":2190},{"color":158,"frequency":2206},{"color":159,"frequency":2222},{"color":160,"frequency":2117},{"color":161,"frequency":2140},{"color":162,"frequency":2062},{"color":163,"frequency":2001},{"color":164,"frequency":1952},{"color":165,"frequency":1941},{"color":166,"frequency":1914},{"color":167,"frequency":1913},{"color":168,"frequency":1895},{"color":169,"frequency":1750},{"color":170,"frequency":1721},{"color":171,"frequency":1804},{"color":172,"frequency":1588},{"color":173,"frequency":1647},{"color":174,"frequency":1640},{"color":175,"frequency":1499},{"color":176,"frequency":1440},{"color":177,"frequency":1469},{"color":178,"frequency":1375},{"color":179,"frequency":1364},{"color":180,"frequency":1306},{"color":181,"frequency":1243},{"color":182,"frequency":1252},{"color":183,"frequency":1227},{"color":184,"frequency":1244},{"color":185,"frequency":1099},{"color":186,"frequency":1069},{"color":187,"frequency":1134},{"color":188,"frequency":1106},{"color":189,"frequency":1054},{"color":190,"frequency":990},{"color":191,"frequency":1002},{"color":192,"frequency":956},{"color":193,"frequency":916},{"color":194,"frequency":976},{"color":195,"frequency":948},{"color":196,"frequency":955},{"color":197,"frequency":839},{"color":198,"frequency":819},{"color":199,"frequency":792},{"color":200,"frequency":793},{"color":201,"frequency":745},{"color":202,"frequency":745},{"color":203,"frequency":718},{"color":204,"frequency":714},{"color":205,"frequency":739},{"color":206,"frequency":687},{"color":207,"frequency":690},{"color":208,"frequency":655},{"color":209,"frequency":643},{"color":210,"frequency":640},{"color":211,"frequency":587},{"color":212,"frequency":615},{"color":213,"frequency":614},{"color":214,"frequency":592},{"color":215,"frequency":565},{"color":216,"frequency":620},{"color":217,"frequency":585},{"color":218,"frequency":570},{"color":219,"frequency":598},{"color":220,"frequency":617},{"color":221,"frequency":745},{"color":222,"frequency":791},{"color":223,"frequency":853},{"color":224,"frequency":832},{"color":225,"frequency":818},{"color":226,"frequency":835},{"color":227,"frequency":817},{"color":228,"frequency":877},{"color":229,"frequency":1013},{"color":230,"frequency":932},{"color":231,"frequency":873},{"color":232,"frequency":872},{"color":233,"frequency":777},{"color":234,"frequency":805},{"color":235,"frequency":850},{"color":236,"frequency":853},{"color":237,"frequency":904},{"color":238,"frequency":979},{"color":239,"frequency":1032},{"color":240,"frequency":1181},{"color":241,"frequency":1352},{"color":242,"frequency":1409},{"color":243,"frequency":1418},{"color":244,"frequency":1703},{"color":245,"frequency":1853},{"color":246,"frequency":1947},{"color":247,"frequency":1905},{"color":248,"frequency":2160},{"color":249,"frequency":2429},{"color":250,"frequency":3035},{"color":251,"frequency":3778},{"color":252,"frequency":4819},{"color":253,"frequency":6378},{"color":254,"frequency":10011},{"color":255,"frequency":12854}];
x.domain(data.map(function(d) { return d.color; }));
y.domain([0, d3.max(data, function(d) { return d.frequency; })]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "begin")
.text("Color value");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Frequency");
svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.color); })
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.frequency); })
.attr("height", function(d) { return height - y(d.frequency); });
function type(d) {
d.frequency = +d.frequency;
return d;
}
</script>