xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<title>LE data</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: white;
font-family: Helvetica, Arial, sans-serif;
}
h1 {
font-size: 24px;
margin: 0;
color: #1aa5ad;
}
h2 {
font-size: 18px;
margin: 0;
color: #1aa5ad;
}
p {
font-size: 12px;
margin: 10px 0 0 0;
}
svg {
background-color: white;
}
circle:hover {
fill: #043639;
}
.axis path,
.axis line {
fill: none;
stroke: #bebebe;
shape-rendering: crispEdges;
}
.axis text {
font-family: Helvetica, Arial, sans-serif;
font-size: 14px;
font-weight: bold;
color:#d6dbe3;
}
p.padding{
padding-left: 5.2cm;
}
</style>
</head>
<body>
<h1>Inequalities in life expectancy for men</h1>
<h2>by English region, 2010 to 2012<br> </h2>
<p>This chart compares life expectancy for men with the slope index of inequality (SII), a measure of how equally life expectancy is distributed within the region. A SII value of zero would represent all areas in the region having the same life expectancy.</p>
<p>There appears to be a negetive correlation for men, with regions with higher life expectancies having a more equal distribution.</p>
<script type="text/javascript">
var w = 600;
var h = 350;
var padding = [ 20, 10, 30, 200 ]; //Top, right, bottom, left
var xScale = d3.scale.linear()
.range([ padding[3], w - padding[1] ]);
var yScale = d3.scale.linear()
.range([ padding[0], h - padding[2] ]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(6);
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left");
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("PHOF_LE_data_EngRegion.csv", function(data) {
//added + to force numeric
data.sort(function(a, b) {
return d3.descending(+a.LE_Male_2011to13, +b.LE_Male_2011to13);
});
xScale.domain([
d3.min(data, function(d) {
return +d.LE_Male_2011to13;
}),
d3.max(data, function(d) {
return +d.LE_Male_2011to13;
})+0.2
]);
yScale.domain([
d3.max(data, function(d) {
return +d.SlopeIndexLE_Male_2011to13;
})+0.5,
d3.min(data, function(d) {
return +d.SlopeIndexLE_Male_2011to13;
}),
]);
var circles = svg.selectAll("circle")
.data(data)
.enter()
.append("circle");
circles.attr("cx", function(d) {
return xScale(d.LE_Male_2011to13);
})
.attr("cy", function(d) {
return yScale(d.SlopeIndexLE_Male_2011to13);
})
.attr("r", 0.1)
.attr("fill", "#1aa5ad")
.append("title")
.text(function(d) {
return "For men in " + d.region + " in 2011-13 life expectancy was " + d.LE_Male_2011to13 + " years" + ", and the slope index of inequality was " + d.SlopeIndexLE_Male_2011to13 + " years.";
});
circles.sort(function(a,b) {
return d3.ascending(+a.LE_Male_2011to13,+b.LE_Male_2011to13);
})
.transition()
.delay(function(d, i) {
return i * 100;
})
.duration(2000)
.attr("r",5);
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>
<p class="padding"><b>age in years</b></p>
<p><b>Source:</b> <a href="https://www.phoutcomes.info/">Public Health Outcomes Framework</a></p>
</body>
</html>
Modified http://d3js.org/d3.v3.js to a secure url
https://d3js.org/d3.v3.js