xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<title>Indices of Multiple Deprivation 2010 Score by Local Authority</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: ;
font-family: Arial
}
svg {
background-color: white;
}
circle {
fill: darkorange
}
h1 {
color: darkblue
}
p {
color: darkslateblue
}
circle:hover {
fill: darkblue;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: Arial;
font-size: 11px;
}
</style>
</head>
<body>
<h1>Deprivation and children's health by Local Authority in England</h1>
<p><em>Source details:</em> X axis = English indices of multiple deprivation 2010 scores by Local Authority area (higher value = more deprived area) <a href="https://www.gov.uk/government/statistics/english-indices-of-deprivation-2010">DCLG 2010</a>. Y axis = % of children aged 0-15 with self-reported bad or very bad health <a href="https://neighbourhood.statistics.gov.uk/dissemination/datasetList.do?JSAllowed=true&Function=&%24ph=60&CurrentPageId=60&step=1&CurrentTreeIndex=-2&searchString=General+Health&datasetFamilyId=2503&Next.x=42&Next.y=8">Census 2011</a> </p>
<script type="text/javascript">
var w = 700;
var h = 600;
var padding = [ 20, 10, 50, 80 ]; //Top, right, bottom, left
var xScale = d3.scale.linear()
.range([ padding[3], w - padding[1] - padding[3] ]);
var yScale = d3.scale.linear()
.range([ padding[0], h - padding[2] ]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(10);
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.tickFormat(function(d) {
return d + "%";
});
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("IMDscatter.csv", function(data) {
//console.log(data);
xScale.domain([
d3.min(data, function(d) {
return +d.IMD2010AverageScore;
}),
d3.max(data, function(d) {
return +d.IMD2010AverageScore;
})
]);
yScale.domain([
d3.max(data, function(d) {
return +d.Badorverybadhealth;
}),
d3.min(data, function(d) {
return +d.Badorverybadhealth;
})
]);
var circles = svg.selectAll("circle")
.data(data)
.enter()
.append("circle");
circles.attr("cx", function(d) {
return xScale(d.IMD2010AverageScore);
})
.attr("cy", function(d) {
return yScale(d.Badorverybadhealth);
})
.attr("r", 0.1)
.attr("fill", "orange")
.append("title")
.text(function(d) {
return d.LAarea + " has an IMD 2010 score of " + d.IMD2010AverageScore + ", and " + d.Badorverybadhealth + "% of children aged 0-15 with self-reported bad or very bad health (Census 2011)";
});
circles.sort(function(a, b) {
return d3.ascending(+a.IMD2010AverageScore, +b.IMD2010AverageScore);
})
.transition()
.delay(function(d, i) {
return i * 10;
})
.duration(500)
.attr("r", 4);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + (h - padding[2] + 10) + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (padding[3] - 10) + ",0)")
.call(yAxis);
});
</script>
</body>
</html>
Modified http://d3js.org/d3.v3.js to a secure url
https://d3js.org/d3.v3.js