Created
January 16, 2013 22:01
-
-
Save michaelcolenso/4551353 to your computer and use it in GitHub Desktop.
Top 10 NFL Rushing Leaders - displayed using d3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import nflgame | |
| allweeks = nflgame.games(2012) | |
| players = nflgame.combine(allweeks) | |
| rushers = players.rushing() | |
| top10 = rushers.sort("rushing_yds").limit(10) | |
| top10.csv('top10rushers.csv') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name | id | home | team | pos | rushing_lngtd | rushing_tds | rushing_twopta | rushing_lng | rushing_yds | rushing_att | rushing_twoptm | receiving_tds | receiving_lng | receiving_rec | receiving_twopta | receiving_yds | receiving_lngtd | receiving_twoptm | fumbles_trcv | fumbles_tot | fumbles_rcv | fumbles_yds | fumbles_lost | defense_ffum | defense_tkl | defense_int | defense_ast | defense_sk | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| A.Peterson | 00-0025394 | no | MIN | RB | 317 | 12 | 1 | 643 | 2097 | 348 | 1 | 1 | 130 | 40 | 0 | 217 | 2 | 0 | 0 | 4 | 0 | 0 | 2 | ||||||
| A.Morris | 00-0029141 | no | WAS | RB | 102 | 13 | 0 | 344 | 1606 | 335 | 0 | 0 | 65 | 11 | 0 | 77 | 0 | 0 | 2 | 4 | 2 | 0 | 3 | ||||||
| M.Lynch | 00-0025399 | no | SEA | RB | 176 | 11 | 0 | 399 | 1590 | 315 | 0 | 1 | 154 | 23 | 0 | 196 | 9 | 0 | 0 | 5 | 0 | 0 | 2 | ||||||
| J.Charles | 00-0026213 | no | KC | RB | 306 | 5 | 0 | 492 | 1513 | 284 | 0 | 1 | 144 | 37 | 0 | 236 | 13 | 0 | 0 | 5 | 0 | 0 | 3 | ||||||
| D.Martin | 00-0029613 | no | TB | RB | 160 | 11 | 0 | 357 | 1454 | 319 | 0 | 1 | 290 | 49 | 0 | 472 | 64 | 0 | 1 | 1 | 1 | 0 | 1 | ||||||
| A.Foster | 00-0026796 | no | HOU | RB | 60 | 15 | 0 | 307 | 1411 | 351 | 0 | 2 | 142 | 40 | 0 | 217 | 5 | 0 | 1 | 3 | 1 | 0 | 2 | ||||||
| S.Ridley | 00-0028011 | no | NE | RB | 47 | 12 | 0 | 250 | 1263 | 290 | 0 | 0 | 36 | 6 | 0 | 51 | 0 | 0 | 0 | 4 | 0 | 0 | 2 | 0 | 1 | 0 | 0 | 0 | |
| C.Spiller | 00-0027861 | no | BUF | RB | 141 | 6 | 0 | 427 | 1244 | 207 | 0 | 2 | 304 | 43 | 0 | 459 | 98 | 0 | 0 | 3 | 0 | 0 | 3 | ||||||
| C.Johnson | 00-0026164 | no | TEN | RB | 276 | 6 | 0 | 450 | 1243 | 276 | 0 | 0 | 143 | 36 | 0 | 226 | 0 | 0 | 0 | 5 | 0 | 0 | 4 | ||||||
| F.Gore | 00-0023500 | no | SF | RB | 51 | 8 | 0 | 291 | 1212 | 259 | 0 | 1 | 149 | 28 | 0 | 234 | 6 | 0 | 4 | 3 | 4 | 15 | 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> | |
| <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> | |
| <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> | |
| <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
| <title></title> | |
| <style> | |
| body { | |
| font: 10px sans-serif; | |
| } | |
| .arc path { | |
| stroke: #fff; | |
| } | |
| </style> | |
| <meta name="description" content=""> | |
| <meta name="viewport" content="width=device-width"> | |
| <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> | |
| <link rel="stylesheet" href="styles/main.css"> | |
| <script src="scripts/vendor/modernizr.min.js"></script> | |
| <script src="http://d3js.org/d3.v3.min.js"></script> | |
| </head> | |
| <body> | |
| <!--[if lt IE 7]> | |
| <p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p> | |
| <![endif]--> | |
| <!-- Add your site or application content here --> | |
| <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> | |
| <script>window.jQuery || document.write('<script src="scripts/vendor/jquery.min.js"><\/script>')</script> | |
| <script> | |
| var width = 960, | |
| height = 500, | |
| radius = Math.min(width, height) / 2; | |
| var color = d3.scale.ordinal() | |
| .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]); | |
| var arc = d3.svg.arc() | |
| .outerRadius(radius - 10) | |
| .innerRadius(radius - 70); | |
| var pie = d3.layout.pie() | |
| .sort(null) | |
| .value(function(d) { return d.rushing_yds; }); | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", width) | |
| .attr("height", height) | |
| .append("g") | |
| .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); | |
| d3.csv("top10rushers.csv", function(error, data) { | |
| data.forEach(function(d) { | |
| d.rushing_yds = +d.rushing_yds; | |
| }); | |
| var g = svg.selectAll(".arc") | |
| .data(pie(data)) | |
| .enter().append("g") | |
| .attr("class", "arc"); | |
| g.append("path") | |
| .attr("d", arc) | |
| .style("fill", function(d) { return color(d.data.rushing_att); }); | |
| g.append("text") | |
| .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; }) | |
| .attr("dy", ".35em") | |
| .style("text-anchor", "middle") | |
| .text(function(d) { return d.data.name; }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment