Skip to content

Instantly share code, notes, and snippets.

@jshumakerpruitt
Created May 20, 2014 19:04
Show Gist options
  • Save jshumakerpruitt/833e2e1b03a71f0b23ee to your computer and use it in GitHub Desktop.
Save jshumakerpruitt/833e2e1b03a71f0b23ee to your computer and use it in GitHub Desktop.
trib_obesity
{"description":"trib_obesity","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"obesity.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"counties.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/u7XvO6a.gif"}
[
{
"count" : 20,
"item" : "ALBANY"
}, {
"count" : 19,
"item" : "ALLEGANY"
}, {
"count" : 18,
"item" : "BROOME"
}, {
"count" : 17,
"item" : "CATTARAUGUS"
}, {
"count" : 16,
"item" : "CHAUTAUQUA"
}, {
"count" : 15,
"item" : "DELAWARE"
}, {
"count" : 14,
"item" : "DUTCHESS"
}, {
"count" : 13,
"item" : "ERIE"
}, {
"count" : 12,
"item" : "MONROE"
}, {
"count" : 11,
"item" : "NASSAU"
}, {
"count" : 10,
"item" : "ONEIDA"
}, {
"count" : 9,
"item" : "ONONDAGA"
}, {
"count" : 8,
"item" : "ORANGE"
}, {
"count" : 7,
"item" : "OTSEGO"
}, {
"count" : 6,
"item" : "RENSSELAER"
}, {
"count" : 5,
"item" : "ST. LAWRENCE"
}, {
"count" : 4,
"item" : "SARATOGA"
}, {
"count" : 3,
"item" : "STEUBEN"
}, {
"count" : 2,
"item" : "SUFFOLK"
}, {
"count" : 1,
"item" : "SULLIVAN"
}]
var data = tributary.obesity;
var names = tributary.counties;
var svg = d3.select("svg");
var margin = 50, height = 300, width = 700
var x_extent = d3.extent(data, function(d){return d.count});
var x_scale = d3.scale.linear().domain(x_extent).range([margin,width])
var y_extent = d3.extent(data, function(d){return d.item});
var y_scale = d3.scale.linear().domain(y_extent).range([height,margin]);
svg.append("rect").attr({
width: width-margin,
height: height-margin,
fill: "LightBlue",
transform: "translate(50,50)"
})
svg.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr({
stroke: "black",
fill: "red",
r: 5,
cx: function(d){return x_scale(d.count)},
cy: function(d){return y_scale(d.item)}
});
var x_axis = d3.svg.axis().scale(x_scale)
var y_axis = d3.svg.axis().scale(y_scale).orient("left")
svg.selectAll("text").data(data).enter().append("text")
.attr({
"class": "scatter_text",
stroke: "black",
"stroke-width": ".2px",
x:function(d) {return x_scale(d.count)},
y:function(d){ return y_scale(d.item) },
"font-size": "12",
transform: "rotate(0)"
}).text(function(x) {return x.item})
var ts = svg.selectAll("text").data(names).enter()
svg.selectAll("text").text(function(d) {return d.item})
svg.append("g")
.attr({
stroke: "black",
fill: "none",
transform: "translate(" + 0 + "," + ( height) +")"
}).call(x_axis)
svg.append("g")
.attr({
"class": "y axis",
stroke: "black",
fill: "none",
transform: "translate(" + margin + ",0)"
}).call(y_axis);
svg.select(".y.axis")
.append("text")
.text("rate of obesity in school-age children")
.attr({
transform: "rotate(91," + (-margin) +",0)",
x: -18,
y: -8
})
[
{
"count": 20,
"item": "16.4"
},
{
"count": 19,
"item": "19.3"
},
{
"count": 18,
"item": "22"
},
{
"count": 17,
"item": "22.3"
},
{
"count": 16,
"item": "19.1"
},
{
"count": 15,
"item": "21.1"
},
{
"count": 14,
"item": "19.7"
},
{
"count": 13,
"item": "20"
},
{
"count": 12,
"item": "21.5"
},
{
"count": 11,
"item": "14"
},
{
"count": 10,
"item": "13.8"
},
{
"count": 9,
"item": "18"
},
{
"count": 8,
"item": "18.6"
},
{
"count": 7,
"item": "16.2"
},
{
"count": 6,
"item": "15.9"
},
{
"count": 5,
"item": "22.8"
},
{
"count": 4,
"item": "19.2"
},
{
"count": 3,
"item": "20.7"
},
{
"count": 2,
"item": "17"
},
{
"count": 1,
"item": "19.5"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment