Skip to content

Instantly share code, notes, and snippets.

@jcdcodes
Last active February 6, 2016 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcdcodes/2f2b420537bdbc20854f to your computer and use it in GitHub Desktop.
Save jcdcodes/2f2b420537bdbc20854f to your computer and use it in GitHub Desktop.
CAFE Standards
year car t2wd t4wd truck
1978 18.0 null null null
1979 19.0 17.2 15.8 17.2
1980 20.0 16.0 14.0 null
1981 22.0 16.7 15.0 null
1982 24.0 18.0 16.0 17.5
1983 26.0 19.5 17.5 19.0
1984 27.0 20.3 18.5 20.0
1985 27.5 19.7 18.9 19.5
1986 26.0 20.5 19.5 20.0
1987 26.0 21.0 19.5 20.5
1988 26.0 21.0 19.5 20.5
1989 26.5 21.5 19.0 20.5
1990 27.5 20.5 19.0 20.0
1991 27.5 20.7 19.1 20.2
1992 27.5 null null 20.2
1993 27.5 null null 20.4
1994 27.5 null null 20.5
1995 27.5 null null 20.6
1996 27.5 null null 20.7
1997 27.5 null null 20.7
1998 27.5 null null 20.7
1999 27.5 null null 20.7
2000 27.5 null null 20.7
2001 27.5 null null 20.7
2002 27.5 null null 20.7
2003 27.5 null null 20.7
2004 27.5 null null 20.7
2005 27.5 null null 21.0
2006 27.5 null null 21.6
2007 27.5 null null 22.2
2008 27.5 null null 22.5
2009 27.5 null null 23.1
2010 27.5 null null 23.5
2011 30.2 null null 24.1
2012 33.3 null null 25.4
2013 34.2 null null 30.5
2014 34.9 null null 31.3
2015 36.2 null null 32.6
2016 37.8 null null 34.1
2017 39.4 null null 34.8
2018 41.4 null null 36.0
2019 43.3 null null 38.2
2020 45.1 null null 39.9
2021 47.1 null null 42.0
2022 48.1 null null 42.9
2023 49.6 null null 44.2
2024 51.3 null null 45.6
2025 52.1 null null 46.2
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<meta charset="utf-8">
<style>
svg {
font: 10px "Gill Sans", sans-serif;
}
.axis path, .axis line{
fill:none;
stroke:black;
stroke-width:1px;
}
.dot {
fill:black;
stroke:none;
}
.line {
fill:none;
stroke:black;
}
</style>
<script src="//d3js.org/d3.v3.min.js"></script>
<body>
<script>
var margin = {top: 20, right: 50, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
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 + ")");
x = d3.scale.linear().domain([1978, 2025]).range([0, width]);
y = d3.scale.linear().domain([0, 53]).range([height, 0]);
var yf = d3.format("d4");
var xAxis = d3.svg.axis().scale(x)
.orient("bottom")
.tickSize(4)
.tickFormat(yf);
d3.csv("cafe.csv", function(data) {
data.forEach(function(d) {d.car = +d.car; });
svg.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.attr("cx", function(d) { return x(d.year); })
.attr("cy", function(d) { return y(d.car);})
.attr("r", 3);
svg.selectAll("text")
.data(data)
.enter().append("text")
.attr("x", function(d) { return x(d.year); })
.attr("y", function(d) { return y(d.car+1); })
.attr("text-anchor", "middle")
.text(function(d) { return d.car; });
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(0,"+(height)+")")
.call(xAxis)
//.selectAll("text")
// .attr("text-anchor", "start")
;
svg.append("line")
.attr("class", "line")
.attr("x1", x(1978)).attr("x2", x(1978))
.attr("y1", y(0.5)).attr("y2", y(17));
svg.append("line")
.attr("class", "line")
.attr("x1", x(1985)).attr("x2", x(1985))
.attr("y1", y(0.5)).attr("y2", y(26.5));
svg.append("line")
.attr("class", "line")
.attr("x1", x(2025)).attr("x2", x(2025))
.attr("y1", y(0.5)).attr("y2", y(51.1));
});
</script>
<p>Many decorations but no lies. And more data.</p>
<p>Data from <em>The Visual Display of Quantitative Information</em>, p. 59; from <a href="http://en.wikipedia.org/wiki/Corporate_Average_Fuel_Economy#Standards_by_model_year.2C_1978-2011">Wikipedia</a>, and <a href="http://www.nhtsa.gov/fuel-economy">NHTSA</a>.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment