Skip to content

Instantly share code, notes, and snippets.

View dougdowson's full-sized avatar

Doug Dowson dougdowson

View GitHub Profile
@dougdowson
dougdowson / index.html
Last active March 18, 2021 06:25
Choropleth
<!DOCTYPE HTML>
<meta charset="utf-8">
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:400italic,600italic,700italic,200,300,400,600,700,900">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
@dougdowson
dougdowson / index.html
Last active April 22, 2020 08:53
Dot Map
<!DOCTYPE HTML>
<meta charset="utf-8">
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:400italic,600italic,700italic,200,300,400,600,700,900">
<script src="http://d3js.org/d3.v3.min.js"></script>
<style>
@dougdowson
dougdowson / data.csv
Last active April 22, 2020 08:53
Map: Tax Statistics
id countyname state returns itemized_pct childcredit_pct mortgageded_pct eitc_pct capgain_pct interest_pct prep_pct
1001 Autauga County AL 24315 0.2947563 0.0549866 0.2432655 0.2092947 0.0882994 0.2997738 0.4894098
1003 Baldwin County AL 87236 0.314549 0.0458526 0.242698 0.1750539 0.156816 0.3474483 0.5373355
1005 Barbour County AL 10648 0.2113073 0.0348422 0.1402141 0.3271037 0.0918482 0.2596732 0.6959053
1007 Bibb County AL 8049 0.2226364 0.0416201 0.1682197 0.2648776 0.0612498 0.2473599 0.6235557
1009 Blount County AL 22330 0.2613524 0.0394089 0.2076131 0.2059113 0.0714734 0.29485 0.680833
1011 Bullock County AL 3952 0.1652328 0.0430162 0.1002024 0.3967611 0.0599696 0.1657389 0.659919
1013 Butler County AL 8690 0.164557 0.0387802 0.1116226 0.3441887 0.0719218 0.2084005 0.6884925
1015 Calhoun County AL 48971 0.2456556 0.0415756 0.1852525 0.2368953 0.0817218 0.3035266 0.619387
1017 Chambers County AL 15398 0.2113262 0.0530588 0.1491752 0.3470581 0.0589038 0.1998961 0.7161969
@dougdowson
dougdowson / chart.js
Last active April 22, 2020 08:52
Map: Cell Towers
var margin = {top: 30, right: 20, bottom: 30, left: 22},
width = 400 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1);
var y = d3.scale.linear()
.rangeRound([height, 0]);
@dougdowson
dougdowson / chart-data.csv
Last active April 22, 2020 08:48
Map: Bank Failures
year month yearmonth date failures
2007 1 200701 2007-01 0
2007 2 200702 2007-02 1
2007 3 200703 2007-03 0
2007 4 200704 2007-04 0
2007 5 200705 2007-05 0
2007 6 200706 2007-06 0
2007 7 200707 2007-07 0
2007 8 200708 2007-08 0
2007 9 200709 2007-09 1
@dougdowson
dougdowson / chart.js
Last active November 12, 2017 23:02
Reusable Bar Chart
d3.svg.barchart = function() {
var margin = {top: 10, right: 10, bottom: 20, left: 0},
width = 760,
height = 350,
padding = 0.25,
duration = 250,
tickFormat = null,
xValue = function(d){ return d[0]; },
yValue = function(d){ return d[1]; },
@dougdowson
dougdowson / chart.js
Last active November 12, 2017 23:00
Line Chart: Prime-Age Workers
var margin = {top: 30, right: 25, bottom: 20, left: 23},
width = 565 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
var parseDate = d3.time.format("%m-%d-%Y").parse,
formatPercent = d3.format(".0"),
formatPercentDetailed = d3.format(".1%"),
numberFormat = d3.format(",.0f");
var x = d3.time.scale()
@dougdowson
dougdowson / chart.js
Last active November 12, 2017 22:03
Stacked Bar Chart
function barStack(d) {
var l = d[0].length
while (l--) {
var posBase = 0, negBase = 0;
d.forEach(function(d) {
d=d[l]
d.size = Math.abs(d.y)
if (d.y<0) {
d.y0 = negBase
negBase-=d.size
@dougdowson
dougdowson / chart.js
Last active August 29, 2015 14:07
Scatterplot: Income Inequality
var margin = {top: 15, right: 20, bottom: 40, left: 40},
width = 575 - margin.left - margin.right,
height = 460 - margin.top - margin.bottom;
var parseYear = d3.time.format("%Y").parse,
parseDate = d3.time.format("%Y%m").parse,
parseMonth = d3.time.format("%m-%Y").parse,
numberFormat = d3.format(",.0f"),
numberFormatDetailed = d3.format(",.1f");
@dougdowson
dougdowson / chart.js
Last active August 29, 2015 14:06
Scatterplot: CO2 Emissions
var margin = {top: 35, right: 45, bottom: 40, left: 25},
width = 565 - margin.left - margin.right,
height = 460 - margin.top - margin.bottom;
var parseYear = d3.time.format("%Y").parse,
parseDate = d3.time.format("%Y%m").parse,
parseMonth = d3.time.format("%m-%Y").parse,
numberFormat = d3.format(",.0f"),
numberFormatDetailed = d3.format(",.1f");