Last active
September 14, 2015 00:55
-
-
Save jchaskell/d3d7a2516364709ff77e to your computer and use it in GitHub Desktop.
US States' Trade with China
This file contains 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> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>States' Trade Relationship with China</title> | |
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script> | |
<style type="text/css"> | |
body { | |
background-color: #ddddff; | |
} | |
svg { | |
background-color: white; | |
} | |
</style> | |
</head> | |
<body> | |
<h2>Trade with China as a Percent of Total Trade in 2014 </h2> | |
<p>Imports from China + Exports from China / Total Imports + Total Exports </p> | |
<script type="text/javascript"> | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", 1000) | |
.attr("height", 510); | |
//Load in contents of CSV file | |
d3.csv("trade_with_china_by_state_wk3.csv", function(data) { | |
data.sort(function(a, b) { | |
return d3.descending(+a.trade_percent_china, +b.trade_percent_china); | |
}); | |
var rects = svg.selectAll("rect") | |
.data(data) | |
.enter() | |
.append("rect"); | |
rects.attr("x", 0) | |
.attr("y", function(d, i) { | |
return i * 10; | |
}) | |
.attr("width", function(d) { | |
return d.trade_percent_china * 30; | |
}) | |
.attr("height", 8) | |
.attr("fill", "crimson") | |
.append("title") | |
//this adds scroll over title with country name and rest of text | |
.text(function(d) { | |
return d.state + ": " + d.trade_percent_china + "%"; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains 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
state | year | exports_total | imports_total | exports_china | imports_china | GDP_millions | trade_percent_china | ||
---|---|---|---|---|---|---|---|---|---|
1 | Alabama | 2014 | 19439656976 | 22210087795 | 3126670408 | 2033874199 | 199440 | 12.3903390894083 | |
2 | Alaska | 2014 | 5110729449 | 2007526150 | 1466861476 | 333486222 | 57080 | 25.2919788136425 | |
3 | Arizona | 2014 | 21247546752 | 19715930777 | 1019115907 | 2707933025 | 284156 | 9.09846809114642 | |
4 | Arkansas | 2014 | 6860016662 | 7602779486 | 437354557 | 2529941697 | 121395 | 20.5167536321138 | |
5 | California | 2014 | 1.73812e+11 | 4.03369e+11 | 16050010176 | 1.37676e+11 | 2311616 | 26.6339346194695 | |
6 | Colorado | 2014 | 8337260753 | 14237309353 | 654843016 | 2267265446 | 306663 | 12.9442485428475 | |
7 | Connecticut | 2014 | 15930667663 | 23892040733 | 907301045 | 2977077366 | 253036 | 9.75417938020049 | |
8 | Delaware | 2014 | 5266627084 | 10689561394 | 456012439 | 504261209 | 62756 | 6.01818942740619 | |
9 | Florida | 2014 | 58506528733 | 71782152022 | 1160026482 | 12255662076 | 839944 | 10.2968949261428 | |
10 | Georgia | 2014 | 39376825754 | 83764608277 | 3082051554 | 18650879121 | 476483 | 17.6487555517088 | |
11 | Hawaii | 2014 | 1447123737 | 5329853601 | 221174936 | 262138112 | 77389 | 7.13169048522499 | |
12 | Idaho | 2014 | 5137445142 | 5691784235 | 481655801 | 1499221201 | 63952 | 18.2919479589854 | |
13 | Illinois | 2014 | 68246837088 | 1.40123e+11 | 4714008061 | 29463893632 | 745875 | 16.4025187957342 | |
14 | Indiana | 2014 | 35467036651 | 48793539329 | 1436395708 | 7721090230 | 317840 | 10.8680552340084 | |
15 | Iowa | 2014 | 15092200558 | 10080923399 | 946360620 | 1411724898 | 170613 | 9.36747271426468 | |
16 | Kansas | 2014 | 12045822292 | 11805856621 | 1183713509 | 2347659479 | 147075 | 14.8055531054264 | |
17 | Kentucky | 2014 | 27650690098 | 39266108135 | 1653540616 | 6860910997 | 188602 | 12.7239375430863 | |
18 | Louisiana | 2014 | 64813659468 | 57605434176 | 8438883476 | 1309776857 | 251397 | 7.96334954198364 | |
19 | Maine | 2014 | 2711573626 | 3860606350 | 183872121 | 357390874 | 55838 | 8.23566909269923 | |
20 | Maryland | 2014 | 12233389310 | 30071548917 | 731811906 | 3127411395 | 348631 | 9.12239436514991 | |
21 | Massachusetts | 2014 | 27382732078 | 34435514986 | 2290935906 | 4405605701 | 459937 | 10.8326294015861 | |
22 | Michigan | 2014 | 55928500991 | 1.22739e+11 | 3403937136 | 8140420830 | 451516 | 6.46136421115641 | |
23 | Minnesota | 2014 | 21408254499 | 34692897614 | 1801259896 | 10384894557 | 316204 | 21.7217543562286 | |
24 | Mississippi | 2014 | 11450139890 | 17254303213 | 644183631 | 3225379650 | 104851 | 13.4807119131866 | |
25 | Missouri | 2014 | 14140665981 | 18283923179 | 872445283 | 4554164578 | 284462 | 16.7360944319826 | |
26 | Montana | 2014 | 1545427741 | 6237281938 | 106274493 | 135777998 | 44269 | 3.1101313165147 | |
27 | Nebraska | 2014 | 7863497581 | 4050191701 | 610290257 | 927640238 | 112159 | 12.9089357511078 | |
28 | Nevada | 2014 | 7691517557 | 7849656312 | 584252675 | 3258993947 | 132064 | 24.729448717295 | |
29 | New Hampshire | 2014 | 4226842551 | 11215615947 | 298542781 | 1105985121 | 71552 | 9.09523507660328 | |
30 | New Jersey | 2014 | 36616205166 | 1.26365e+11 | 1425370024 | 18111852950 | 549099 | 11.9874085813152 | |
31 | New Mexico | 2014 | 3800450987 | 2237304630 | 105893888 | 781283409 | 92959 | 14.6938258730123 | |
32 | New York | 2014 | 88433809412 | 1.3458e+11 | 4290507924 | 23074327027 | 1404518 | 12.2704665792447 | |
33 | North Carolina | 2014 | 31376674756 | 52863883680 | 2661378529 | 12486268679 | 483126 | 17.9814183206158 | |
34 | North Dakota | 2014 | 5492795154 | 3829392074 | 49960606 | 152513068 | 55136 | 2.17195459657636 | |
35 | Ohio | 2014 | 52240104252 | 70268895120 | 3881651849 | 12670668757 | 583261 | 13.5111058704665 | |
36 | Oklahoma | 2014 | 6308690348 | 13588520904 | 273496793 | 2649791970 | 183501 | 14.6919521835311 | |
37 | Pennsylvania | 2014 | 40354943154 | 13787777664 | 4264840885 | 2631653191 | 215677 | 12.7376200748804 | |
38 | Puerto Rico | 2014 | 20238018075 | 83086063845 | 2398383171 | 18097788090 | 662890 | 19.8367804292415 | |
39 | Rhode Island | 2014 | 2388748799 | 8353607988 | 115841904 | 1135537256 | 54960 | 11.6490187843544 | |
40 | South Carolina | 2014 | 29624187799 | 37728697389 | 4228389229 | 5538523165 | 190304 | 14.5011046917113 | |
41 | South Dakota | 2014 | 1593697270 | 1041924500 | 39281446 | 143404248 | 45867 | 6.9314078400559 | |
42 | Tennessee | 2014 | 32940171718 | 69754014293 | 2333992810 | 25333886659 | 300604 | 26.9420115624037 | |
43 | Texas | 2014 | 2.88049e+11 | 3.02277e+11 | 10947592596 | 45446796290 | 1648036 | 9.55309250922372 | |
44 | Utah | 2014 | 12305529420 | 11118424611 | 891716624 | 2007287296 | 141410 | 12.3762363782108 | |
45 | Vermont | 2014 | 3669277804 | 4759797794 | 274869724 | 226113141 | 29613 | 5.94350897883595 | |
46 | Virginia | 2014 | 19255244148 | 24286941582 | 2000142373 | 5855261491 | 463613 | 18.0409038551956 | |
47 | Washington | 2014 | 90547036334 | 52378630833 | 20689637743 | 8302348527 | 427052 | 20.2846604424974 | |
48 | West Virginia | 2014 | 7486181404 | 3811090386 | 549490885 | 278680173 | 75337 | 7.33071730409347 | |
49 | Wisconsin | 2014 | 23428059266 | 23524598717 | 1560985127 | 6063467237 | 292891 | 16.2385958357471 | |
50 | Wyoming | 2014 | 1757198477 | 1901836758 | 19014795 | 128846273 | 44190 | 4.04098508223302 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment