Skip to content

Instantly share code, notes, and snippets.

@bguiz
Last active September 28, 2018 03:08
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 bguiz/e58ae3e2dda678c1b37f98f97dc491df to your computer and use it in GitHub Desktop.
Save bguiz/e58ae3e2dda678c1b37f98f97dc491df to your computer and use it in GitHub Desktop.
license: gpl-3.0
height: 700
border: no

Wind Capacity by state

  • Wind energy installed capacity in Megawatts. Source.
  • US 2016 presidential election results takes into account only the two party vote count. Source.
  • Size of bubbles represents total two party vote count.
  • Colour of bubbles represents party leaning.
  • Created with the intent to improve upon the "Political Winds" infographic that appeared in The Wall Street Journal. Source.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v4.min.js"></script>
<script src="http://dimplejs.org/dist/dimple.v2.3.0.min.js"></script>
<style>
</style>
<title>Wind Capacity by state</title>
</head>
<body>
<script type="text/javascript">
function drawChart(data) {
var margin = 75,
width = 1200 - margin,
height = 600 - margin;
var svg = d3.select("body")
.append("svg")
.attr("width", width + margin)
.attr("height", height + margin)
.append('g')
.attr('class','chart');
const myChart = new dimple.chart(svg, data);
myChart.setBounds(margin, margin, width - margin, height - margin);
const xAxis = myChart.addCategoryAxis("x", "State");
xAxis.addOrderRule("TrumpPercent");
const yAxis = myChart.addMeasureAxis("y", "Capacity");
myChart.addMeasureAxis("z", "TwoPartyVoters");
const colourAxis = myChart.addColorAxis(
"TrumpPercent",
["#0000FF", "#0000FF", "#AAAAAA", "#FF0000", "#FF0000"],
);
colourAxis.overrideMin = 0;
colourAxis.overrideMax = 100;
myChart.addSeries(null, dimple.plot.bubble);
myChart.draw();
};
const entriesToDiscard = [
"",
"Nationwide",
"Year",
"Region",
"The Midwest",
"The Northeast",
"The South",
"The West",
];
function parseCsvValueAsNumber(str) {
if (typeof str !== 'string') {
return str;
}
return +(str.trim().replace(/\,/g, "",));
}
function preProcessData(cb) {
d3.csv("us-elections.csv", (elections) => {
d3.csv("wind.csv", (wind) => {
const windMap = new Map();
wind.forEach((windEntry) => {
const { State, Capacity } = windEntry;
windMap.set(State, windEntry);
});
const stateMap = new Map();
elections.forEach((electionsEntry) => {
const { State } = electionsEntry;
if (entriesToDiscard.indexOf(State) >= 0) {
return;
}
const windEntry = windMap.get(State);
const Capacity = windEntry ?
parseCsvValueAsNumber(windEntry.Capacity) : 0;
let {
'2016_clinton': Clinton,
'2016_trump': Trump,
} = electionsEntry;
([
Clinton,
Trump,
] = [
parseCsvValueAsNumber(Clinton),
parseCsvValueAsNumber(Trump),
]);
const TwoPartyVoters = (Clinton + Trump);
const TrumpPercent = Math.round(Trump / TwoPartyVoters * 10000) / 100;
const stateEntry = {
State,
Capacity,
Clinton,
Trump,
TwoPartyVoters,
TrumpPercent,
};
stateMap.set(State, stateEntry);
});
const data = [...stateMap.values()];
cb(data);
});
});
}
preProcessData(drawChart);
</script>
</body>
</html>
State Total 2016_clinton 2016_trump 2016_johnson Total Obama, Barack - Democratic Romney, Mitt - Republican Total Obama, Barack - Democratic McCain, John - Republican Total Kerry, John - Democratic Bush, George W. - Republican Total Gore, Al - Democratic Bush, George W. - Republican Nader, Ralph - Green Total Clinton, Bill - Democratic Dole, Bob - Republican Perot, Ross - Reform Total Clinton, Bill - Democratic Bush, George H.W. - Republican Perot, Ross - Independent Total Dukakis, Michael - Democratic Bush, George H.W. - Republican Total Mondale, Walter - Democratic Reagan, Ronald - Republican Total Carter, Jimmy - Democratic Reagan, Ronald - Republican Anderson, John - Independent Total
Year 2016 2012 2008 2004 2000 1996 1992 1988 1984 1980 1976
Nationwide 137,098,601 65853625 62985106 4489233 129235558 65918507 60934407 131473705 69499428 59950323 122303590 59027115 62039572 105425985 51009810 50462412 2883443 96275640 47400125 39198755 8085402 104426611 44909806 39104550 19743821 91594686 41809476 48886597 92653233 37577352 54455472 86509678 35480115 43903230 5719850 81540780
Alabama 2,123,372 729547 1318255 44467 2074338 795696 1255925 2099819 813479 1266546 1883449 693933 1176394 1672551 695602 944409 18349 1534349 662165 769044 92149 1688060 690080 804283 183109 1378476 549506 815576 1441713 551899 872849 1341929 636730 654192 16481 1182850
Alaska 318,608 116454 163387 18725 300495 122640 164676 326197 123594 193841 312598 111025 190889 285560 79004 167398 28747 241620 80380 122746 26333 258506 78294 102000 73481 200116 72584 119251 207605 62007 138377 158445 41842 86112 11155 123574
Arizona 2,604,657 1161167 1252401 106327 2306559 1025232 1233654 2303838 1034707 1230111 2016102 893524 1104294 1534113 685341 781652 45645 1404405 653288 622073 112072 1487006 543050 572086 353741 1171873 454029 702541 1025897 333854 681416 873945 246843 529688 76952 742719
Arkansas 1,130,635 380494 684872 29829 1069468 394409 647744 1086617 422310 638017 1054945 469953 572898 921781 422768 472940 13421 884262 475171 325416 69884 950653 505823 337324 99132 827738 349237 466578 884406 338646 534774 837582 398041 403164 22468 769396
California 14,237,884 8753788 4483810 478500 13055815 7854285 4839958 13583083 8274473 5011781 12421859 6745485 5509826 10965856 5861203 4567429 418707 10019484 5119835 3828380 697847 11131721 5121325 3630574 2296006 9887064 4702233 5054917 9505423 3922519 5467009 8587063 3083661 4524858 739833 7867117
Colorado 2,780,247 1338870 1202484 144121 2571846 1323102 1185243 2401462 1288633 1073629 2130325 1001725 1101256 1741365 738227 883745 91434 1510704 671152 691848 99629 1569180 629681 562850 366010 1372394 621453 728177 1295381 454974 821818 1184415 367973 652264 130633 1081135
Connecticut 1,644,920 897572 673215 48676 1558993 905109 634899 1646793 997773 629428 1578769 857488 693826 1459525 816015 561094 64452 1392614 735740 483109 139523 1616332 682318 578313 348771 1443394 676584 750241 1466900 569597 890877 1406285 541732 677210 171807 1381526
Delaware 443,814 235603 185127 14757 413921 242584 165484 412616 255459 152374 375270 200152 171660 327622 180068 137288 8307 271084 140355 99062 28719 289735 126054 102313 59213 249891 108647 139639 254572 101656 152190 235668 105754 111252 16288 235834
Florida 9,501,617 4504975 4617886 207043 8492175 4237756 4163447 8412248 4282367 4046219 7609810 3583544 3964522 5963110 2912253 2912790 97488 5303794 2546870 2244536 483870 5314392 2072698 2173310 1053067 4302313 1656701 2618885 4180051 1448816 2730350 3687026 1419475 2046951 189692 3150631
Georgia 4,141,445 1877963 2089104 125306 3908369 1773827 2078688 3932158 1844123 2048759 3304481 1366149 1914254 2596804 1116230 1419720 13432 2299071 1053849 1080843 146337 2321133 1008966 995252 309657 1809672 714792 1081331 1776093 706628 1068722 1597467 890733 654168 36055 1467458
Hawaii 428,937 266891 128847 15954 434697 306658 121015 453568 325871 120566 429013 231708 194191 367951 205286 137845 21623 360120 205012 113943 27358 372842 179310 136822 53003 354461 192364 158625 335846 147154 185050 303287 135879 130112 32021 291301
Idaho 690,433 189765 409055 28331 656742 212787 420911 658454 236440 403012 598447 181098 409235 501621 138637 336937 12292 491719 165443 256595 62518 482142 137013 202645 130395 408968 147272 253881 411144 108510 297523 437431 110192 290699 27058 340932
Illinois 5,594,420 3,090,729 2,146,015 209,596 5251432 3019512 2135216 5530179 3419348 2031179 5274322 2891550 2345946 4742123 2589026 2019421 103759 4311391 2341744 1587021 346408 5050157 2453350 1734096 840515 4559120 2215940 2310939 4819088 2086499 2707103 4749721 1981413 2358049 346754 4718833
Indiana 2,757,828 1033126 1557286 133993 2633143 1154275 1422872 2756658 1374039 1345648 2468002 969011 1479438 2199302 901980 1245836 18531 2135842 887424 1006693 224299 2305871 848420 989375 455934 2168621 860643 1297763 2233069 841481 1377230 2242033 844197 1255656 111639 2220362
Iowa 1,566,031 653,669 800,983 59,186 1582180 822544 730617 1537123 828940 682379 1506908 741898 751957 1315563 638517 634373 29374 1234075 620258 492644 105159 1354607 586353 504891 253468 1225614 670557 545355 1319805 605620 703088 1317661 508672 676026 115633 1279306
Kansas 1,194,755 427,005 671,018 55,406 1156254 439908 689809 1238873 514765 699655 1187756 434993 736456 1072216 399276 622332 36086 1074300 387659 583245 92639 1157236 390434 449951 312358 993044 422636 554049 1021991 333149 677296 979795 326150 566812 68231 957845
Kentucky 1,924,149 628,854 1,202,971 53,752 1798048 679370 1087190 1827587 751985 1048462 1796079 712733 1069439 1544187 638898 872492 23192 1388708 636614 623283 120396 1492900 665104 617178 203944 1322517 580368 734281 1370461 539589 822782 1294627 616417 635274 31127 1167142
Louisiana 2,029,032 780,154 1,178,638 37,978 1994065 809141 1152262 1960761 782989 1148275 1943106 820299 1102169 1765656 792344 927871 20473 1783959 927837 712586 123293 1790017 815971 733386 211478 1628202 717460 883702 1706822 651586 1037299 1548591 708453 792853 26345 1278439
Maine 747,927 357,735 335,593 38,105 713180 401306 292276 731163 421923 295273 740752 396842 330201 651817 319951 286616 37127 605897 312788 186378 85970 679499 263420 206504 206820 555035 243569 307131 553144 214515 336500 523011 220974 238522 53327 483208
Maryland 2,781,446 1,677,928 943,169 79,605 2707327 1677844 971869 2631596 1629467 959862 2386678 1334493 1024703 2025480 1145782 813797 53768 1780870 966207 681530 115812 1985046 988571 707094 281414 1714358 826304 876167 1675873 787935 879918 1540496 726161 680606 119537 1432273
Massachusetts 3,325,046 1,995,196 1,090,893 138,018 3167767 1921761 1188460 3081069 1904098 1108854 2912388 1803800 1071109 2702984 1616487 878502 173564 2556785 1571763 718107 227217 2773574 1318662 805049 632312 2632805 1401406 1194644 2559453 1239606 1310936 2524298 1053802 1057631 382539 2547558
Michigan 4,824,260 2,268,839 2,279,543 172,136 4745316 2564569 2115256 5010606 2872579 2048639 4839252 2479183 2313746 4232711 2170418 1953139 84165 3848844 1989653 1481212 336670 4274673 1871182 1554940 824813 3669163 1675783 1965486 3801658 1529638 2251571 3909725 1661532 1915225 275223 3653749
Minnesota 2,945,233 1,367,825 1,323,232 112,984 2936561 1546167 1320225 2910369 1573354 1275409 2828387 1445014 1346695 2438685 1168266 1109659 126696 2192640 1120438 766476 257704 2347948 1020997 747841 562506 2096790 1109471 962337 2084449 1036364 1032603 2051953 954174 873241 174990 1949931
Mississippi 1,211,088 485,131 700,714 14,435 1285584 562949 710746 1289939 554662 724597 1152365 458094 684981 994926 404964 573230 8126 893857 394022 439838 52222 981793 400258 487793 85626 931527 363921 557890 940192 352192 581477 892620 429281 441089 12036 769360
Missouri 2,827,673 1,071,068 1,594,511 97,359 2763689 1223796 1482440 2929111 1441911 1445814 2731364 1259171 1455713 2359892 1111138 1189924 38515 2158065 1025935 890016 217188 2391565 1053873 811159 518741 2093228 1001619 1084953 2122771 848583 1274188 2099824 931182 1074181 77920 1953600
Montana 501,822 177,709 279,240 28,037 484484 201839 267928 492750 232159 243882 450445 173710 266063 410997 137126 240178 24437 407261 167922 179652 55229 410611 154507 144207 107225 365674 168936 190412 384377 146742 232450 363952 118032 206814 29281 328734
Nebraska 844,227 284,494 495,961 38,946 794379 302081 475064 801281 333319 452979 778186 254328 512814 697019 231780 433862 24540 677415 236761 363467 71278 739283 217344 344346 174687 662372 259646 398447 652090 187866 460054 640854 166851 419937 44993 607668
Nevada 1,125,385 539,260 512,058 37,384 1014918 531373 463567 967848 533736 412827 829587 397190 418690 608970 279978 301575 15008 464279 203974 199244 43986 506318 189148 175828 132580 350067 132738 206040 286667 91655 188770 247885 66666 155017 17651 201876
New Hampshire 744,296 348,526 345,790 30,777 710972 369561 329918 710970 384826 316534 677738 340511 331237 569081 266348 273559 22198 499175 246214 196532 48390 537945 209040 202484 121337 450525 163696 281537 388954 120395 267051 383999 108864 221705 49693 339618
New Jersey 3,906,723 2,148,278 1,601,933 72,477 3651140 2126610 1478749 3877407 2215422 1613207 3612137 1911430 1670003 3187226 1788850 1284173 94554 3075807 1652329 1103078 262134 3343594 1436206 1356865 521829 3099553 1320352 1743192 3217862 1261323 1933630 2975684 1147364 1546557 234632 3014472
New Mexico 798,319 385,234 319,667 74,541 783757 415335 335788 830158 472422 346832 756304 370942 376930 598605 286783 286417 21251 556074 273495 232751 32257 569986 261617 212824 91895 521287 244497 270341 514370 201769 307101 456237 167826 250779 29459 416590
New York 7,721,453 4,556,124 2,819,534 176,598 7081536 4485877 2490496 7640948 4804945 2752771 7391954 4314280 2962567 6831178 4113791 2405676 244398 6316129 3756177 1933492 503458 6926925 3444450 2346649 1090721 6485683 3347882 3081871 6806810 3119609 3664763 6201959 2728372 2893831 467801 6534420
North Carolina 4,741,564 2,189,316 2,362,631 130,126 4505372 2178391 2270395 4310789 2142651 2128474 3501007 1525849 1961166 2911262 1257692 1631163 0 2515807 1107849 1225938 168059 2611850 1114042 1134661 357864 2134370 890167 1237258 2175361 824287 1346481 1855833 875635 915018 52800 1677906
North Dakota 344,360 93,758 216,794 21,434 322627 124827 188163 317738 141403 168887 312833 111052 196651 288267 95284 174852 9497 266411 106905 125050 32515 308133 99168 136244 71084 297261 127739 166559 308971 104429 200336 301545 79189 193695 23640 297094
Ohio 5,536,528 2,394,164 2,841,005 174,498 5590934 2827709 2661437 5721831 2940044 2677820 5627908 2741167 2859768 4705457 2186190 2351209 117857 4534434 2148222 1859883 483207 4939964 1984942 1894310 1036426 4393699 1939629 2416549 4547619 1825440 2678560 4283603 1752414 2206545 254472 4111873
Oklahoma 1,452,992 420,375 949,136 83,481 1334872 443547 891325 1462661 502496 960165 1463758 503966 959792 1234229 474276 744337 0 1206713 488105 582315 130788 1390359 473066 592929 319878 1171036 483423 678367 1255676 385080 861530 1149708 402026 695570 38284 1092251
Oregon 2,001,336 1,002,106 782,403 94,231 1789270 970488 754175 1827864 1037291 738475 1836782 943163 866831 1533968 720342 713577 77357 1377760 649641 538152 121221 1462643 621314 475757 354091 1201694 616206 560126 1226527 536479 685700 1181516 456890 571044 112389 1029876
Pennsylvania 6,166,708 2,926,441 2,970,733 146,715 5754939 2990274 2680434 6015476 3276363 2655885 5769590 2938095 2793847 4913119 2485967 2281127 103392 4506118 2215819 1801169 430984 4959810 2239164 1791841 902667 4536251 2194944 2300087 4844903 2228131 2584323 4561501 1937540 2261872 292921 4620787
Rhode Island 464,144 252,525 180,543 14,746 446049 279677 157204 471766 296571 165391 437134 259760 169046 409112 249508 130555 25052 390284 233050 104683 43723 453478 213299 131601 105045 404620 225123 177761 410492 197106 212080 416072 198342 154793 59819 411170
South Carolina 2,103,027 855,373 1,155,389 49,204 1964118 865941 1071645 1920969 862449 1034896 1617730 661699 937974 1383777 566039 786426 20279 1149457 504051 573458 64386 1202527 479514 577507 138872 986009 370554 606443 968540 344470 615539 890083 427560 441207 14150 802594
South Dakota 370,093 117,458 227,721 20,850 363815 145039 210610 381975 170924 203054 388215 149244 232584 316269 118804 190700 0 323826 139333 150543 31250 336254 124888 136718 73295 312991 145560 165415 317867 116113 200267 327703 103855 198343 21431 300678
Tennessee 2,508,027 870,695 1,522,925 70,397 2460904 960709 1462330 2601982 1087437 1479178 2434949 1035160 1383336 2076181 981720 1061949 19781 1894105 909146 863530 105918 1982638 933521 841300 199968 1636250 679794 947233 1711993 711714 990212 1617616 783051 787761 35991 1476346
Texas 8,969,226 3,877,868 4,685,047 283,492 7999532 3308124 4569843 8087791 3528633 4479328 7410765 2832704 4526917 6407637 2433746 3799639 137994 5611644 2459683 2736167 378537 6154018 2281815 2496071 1354781 5427410 2352748 3036829 5397571 1949276 3433428 4541637 1881147 2510705 111613 4071884
Utah 1,143,601 310,676 515,231 39,608 1020861 251813 740600 958996 327670 596030 927844 241199 663742 770754 203053 515096 35850 665629 221633 361911 66461 744069 183429 322632 203400 647008 207343 428442 629656 155369 469105 604222 124266 439687 30284 541198
Vermont 315,067 178,573 95,369 10,078 299290 199239 92698 325046 219262 98974 312309 184067 121180 294308 149022 119775 20374 258449 137894 80352 31024 289701 133592 88122 65991 243333 115775 124331 234561 95730 135865 213207 81891 94598 31760 187855
Virginia 3,982,752 1,981,473 1,769,443 118,274 3854489 1971820 1822522 3723260 1959532 1725005 3198367 1454742 1716959 2739447 1217290 1437490 59398 2416642 1091060 1138350 159861 2558665 1038650 1150517 348639 2191609 859799 1309162 2146635 796250 1337078 1866032 752174 989609 95418 1697094
Washington 3,316,996 1,742,718 1,221,747 160,879 3145958 1755396 1290670 3053261 1750848 1229216 2861713 1510201 1304894 2488745 1247652 1108864 103002 2253837 1123323 840712 201003 2288230 993037 731234 541780 1865253 933516 903835 1883910 807352 1051670 1742394 650193 865244 185073 1555534
West Virginia 721,231 188,794 489,371 23,004 672119 238269 417655 715123 303857 397466 755887 326541 423778 648124 295497 336475 10680 636459 327812 233946 71639 683711 331001 241974 108829 653311 341016 310065 735742 328125 405483 737715 367462 334206 31691 750674
Wisconsin 2,976,150 1,382,536 1,405,284 106,674 3068434 1620985 1407966 2983417 1677211 1262393 2997007 1489504 1478120 2598607 1242987 1237279 94070 2196169 1071971 845029 227339 2531114 1041066 930855 544479 2191608 1126794 1047499 2212016 995847 1198800 2273221 981584 1088845 160657 2101336
Wyoming 255,849 55,973 174,419 13,287 249061 69286 170962 254658 82868 164958 243428 70776 167629 218351 60481 147947 4625 211571 77934 105388 25928 200625 68160 79347 51263 176551 67113 106867 188968 53370 133241 176713 49427 110700 12072 156343
Washington DC 311,268 282,830 12,723 4,906 293764 267070 21381 265853 245800 17367 227586 202970 21256 201894 171923 18073 10576 185726 158220 17339 3611 227572 192619 20698 9681 192877 159407 27590 211288 180408 29009 173889 130231 23313 16131 168830
Region
The Midwest 31,781,558 14,184,671 15,559,353 1,203,062 31208764 15791412 14839675 32119161 17287837 14293856 30940140 14966115 15709888 26966111 12853666 13162586 683090 24953412 12076303 10151279 2425656 27736805 11692017 10234726 5668306 24663511 11556017 12915351 25441394 10511029 14761096 25177638 10291213 12826555 1675583 24152275
The Northeast 28,572,812 15,857,331 11,254,622 775,458 26798878 15866912 10503868 27810703 16651909 10765920 26422305 14743888 11360635 23573346 13303712 9190235 857762 21838938 12126556 7404831 1920565 24083211 11247395 8337533 4345801 22008325 10783689 11004191 22624812 10116011 12397142 21156069 8981027 9961890 1896255 21357551
The South 46,540,157 19,771,012 24,726,382 1,270,788 43413453 19219949 23601717 43431704 19838970 23125387 39126698 16445366 22394579 32859672 14209319 17920931 442613 29518827 13584234 13549250 2167339 31122716 12810509 13183485 4974844 26400440 10909486 15283600 26691256 9928558 16638004 23858466 10588185 12301767 714151 21354025
The West 30,204,074 16,040,611 11,444,749 1,239,925 27814463 15040234 11989147 28112137 15720712 11765160 25814447 12871746 12574470 22026856 10643113 10188660 899978 19964463 9613032 8093395 1571842 21483879 9159885 7348806 4754870 18522410 8560284 9683455 17895771 7021754 10659230 16317505 5619690 8813018 1433861 14676929
State Capacity
Texas 50
Iowa 74
Oklahoma 45
California 61
Kansas 10
Illinois 26
Minnesota 99
Oregon 13
Washington 75
Colorado 29
North Dakota 96
Indiana 97
New York 29
Michigan 60
Wyoming 89
New Mexico 83
Pennsylvania 69
Nebraska 35
South Dakota 77
Idaho 73
Maine 1
Montana 95
West Virginia 86
Missouri 59
Wisconsin 48
Ohio 45
Utah 91
Arizona 68
North Carolina 8
Hawaii 6
Maryland 91
New Hampshire 85
Nevada 52
Puerto Rico 25
Vermont 19
Massachusetts 15
Alaska 62
Rhode Island 54
Tennessee 29
New Jersey 9
Connecticut 5
Delaware 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment