Skip to content

Instantly share code, notes, and snippets.

@maggie-lee
Created September 15, 2014 13:07
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 maggie-lee/742235d81399fd363460 to your computer and use it in GitHub Desktop.
Save maggie-lee/742235d81399fd363460 to your computer and use it in GitHub Desktop.
Percent of outpatient doctor visits for influenza-like symptoms
YEAR WEEK ILITOTAL TOTAL PATIENTS NUM OF PROVIDERS PERCENT_WEIGHTED_ILI PERCENT_UNWEIGHTED_ILI
2008 1 9706 430603 1486 2.439387548 2.254048393
2008 2 11115 531444 1509 2.29319128 2.091471538
2008 3 12197 516966 1511 2.629066086 2.359342781
2008 4 17171 516683 1508 3.929656224 3.323314295
2008 5 24812 559609 1514 4.992016051 4.433810035
2008 6 31896 596692 1526 5.777595567 5.345471365
2008 7 31625 583210 1518 5.98317541 5.422575059
2008 8 30245 570334 1497 5.616767538 5.30303296
2008 9 25027 589626 1453 4.53234006 4.244555023
2008 10 20254 558269 1445 3.832486291 3.628000122
2008 11 16714 550776 1412 3.215218113 3.034627507
2008 12 13040 514205 1395 2.692446472 2.535953559
2008 13 10376 504350 1379 2.033655835 2.057301477
2008 14 8583 492850 1327 1.652750483 1.7415035
2008 15 7045 500881 1318 1.311296364 1.406521709
2008 16 6079 479187 1288 1.165197081 1.268607037
2008 17 4953 459808 1208 1.020347634 1.07718874
2008 18 4224 425187 1147 0.877607228 0.993445237
2008 19 4011 440183 1098 0.825106626 0.911211928
2008 20 3904 401601 1074 0.787314875 0.972109133
2008 21 3646 367075 945 0.805438573 0.993257509
2008 22 3803 348477 869 0.886061332 1.091320231
2008 23 2933 330127 789 0.743742683 0.888445962
2008 24 2906 327366 764 0.706842045 0.887691452
2008 25 2842 321789 755 0.655943482 0.88318743
2008 26 2534 306499 730 0.633491767 0.826756368
2008 27 2405 307073 713 0.571837181 0.783201389
2008 28 2431 311423 710 0.558278241 0.780610295
2008 29 2319 301532 696 0.597893282 0.769072603
2008 30 2166 300292 694 0.577221624 0.721297937
2008 31 2289 304175 676 0.596987365 0.752527328
2008 32 2220 294930 668 0.564652873 0.752720985
2008 33 2368 298701 657 0.585681703 0.79276601
2008 34 2237 300714 657 0.503985403 0.743896194
2008 35 2429 298342 636 0.468139144 0.814166292
2008 36 2461 293535 666 0.576454849 0.838400872
2008 37 2788 327567 685 0.681360615 0.851123587
2008 38 3735 336560 679 0.794763739 1.109757547
2008 39 3400 329731 716 0.868115785 1.031143569
2008 40 5687 555999 1435 1.068281365 1.022843566
2008 41 5959 578446 1500 1.007556409 1.030173949
2008 42 5896 582351 1525 0.979398906 1.012447819
2008 43 6485 598473 1527 1.049429449 1.083591073
2008 44 6987 599343 1545 1.132182469 1.165776525
2008 45 7297 612526 1555 1.131560877 1.191296369
2008 46 7667 598635 1555 1.154693178 1.280747033
2008 47 7733 608646 1563 1.204480411 1.270525067
2008 48 7634 478386 1523 1.360813268 1.595782485
2008 49 8708 597052 1551 1.303219081 1.458499427
2008 50 8689 579573 1543 1.302042279 1.499207175
2008 51 7812 479318 1416 1.45108668 1.629815696
2008 52 8706 403876 1484 1.799273677 2.155612119
2008 53 8603 425780 1490 2.121336633 2.020527033
2009 1 8956 579428 1539 1.471378404 1.545662274
2009 2 9289 565631 1512 1.615549611 1.642236723
2009 3 11456 582932 1566 1.953326026 1.965237798
2009 4 14324 611176 1554 2.42906504 2.343678417
2009 5 18268 638613 1580 2.966860533 2.860574401
2009 6 21667 648304 1569 3.573536976 3.342104938
2009 7 20022 624583 1543 3.366529007 3.205658816
2009 8 20450 659573 1544 3.296195848 3.100490772
2009 9 18441 623389 1534 3.172267976 2.958185018
2009 10 15711 637672 1524 2.580404995 2.463805844
2009 11 13277 605503 1494 2.429222856 2.192722414
2009 12 11400 608342 1470 1.990279292 1.873945905
2009 13 9669 586651 1440 1.724225844 1.648169014
2009 14 8460 564460 1422 1.603548394 1.498777593
2009 15 7222 558837 1415 1.284178496 1.292326743
2009 16 7348 577836 1445 1.293200231 1.271641088
2009 17 18627 624734 1405 2.740123312 2.981588964
2009 18 14578 598189 1422 2.223911451 2.437022413
2009 19 12554 550300 1372 1.766568389 2.281301108
2009 20 20774 544432 1331 1.921705672 3.81571987
2009 21 22394 531526 1314 1.861104257 4.21315232
2009 22 17105 538177 1305 1.684227731 3.178322373
2009 23 12392 493761 1296 1.739302929 2.509716239
2009 24 10780 521701 1280 1.830014311 2.06631768
2009 25 8801 512268 1279 1.581280179 1.718046023
2009 26 7422 475877 1237 1.491724676 1.559646715
2009 27 6290 480680 1246 1.388995043 1.308562869
2009 28 5964 502466 1248 1.347020581 1.186945982
2009 29 5735 503971 1248 1.160564411 1.137962303
2009 30 5587 485804 1254 1.208500788 1.150052284
2009 31 5526 496666 1230 1.155441277 1.112618943
2009 32 5877 506019 1234 1.145178851 1.16141884
2009 33 8941 544827 1286 1.466396144 1.641071386
2009 34 14556 588916 1320 2.380171618 2.471659795
2009 35 21350 573972 1358 3.446813099 3.719693644
2009 36 22561 571201 1367 4.053148738 3.949747987
2009 37 26091 638302 1380 4.266208693 4.087563567
2009 38 24454 608464 1313 4.21579403 4.018972363
2009 39 27919 606458 1331 4.886097941 4.603616409
2009 40 48420 855346 2056 6.069228867 5.660867064
2009 41 58196 853912 2134 7.094668029 6.815222177
2009 42 69068 906536 2162 7.715102298 7.618892134
2009 43 66411 898860 2167 7.551343812 7.388358588
2009 44 57017 899425 2197 6.671178189 6.339272313
2009 45 42729 864348 2191 5.206326288 4.943494981
2009 46 32520 853552 2157 4.044774799 3.809961197
2009 47 22508 654101 2146 3.497217284 3.441058797
2009 48 21730 814550 2122 2.690227291 2.667730649
2009 49 19325 781811 2093 2.471187845 2.471825032
2009 50 17081 728401 2014 2.447727493 2.344999526
2009 51 14575 536961 1934 2.645938416 2.714349832
2009 52 15613 583299 1937 2.615670398 2.676671827
2010 1 14299 721138 1996 1.907117604 1.982838236
2010 2 14088 770895 2016 1.8673753 1.827486234
2010 3 14757 766177 2053 1.880723306 1.926056251
2010 4 15122 785580 2026 1.969084332 1.924947173
2010 5 16037 767773 1996 2.113868111 2.088768425
2010 6 15381 756068 1977 2.096945831 2.034340826
2010 7 15065 762208 1954 1.902943456 1.976494605
2010 8 16087 806925 1990 1.969514623 1.993617746
2010 9 14486 781411 1953 1.923310367 1.853825964
2010 10 14354 768702 1946 1.896586165 1.867303584
2010 11 12601 741293 1933 1.751805551 1.699867664
2010 12 11191 747358 1917 1.526319223 1.497408203
2010 13 10359 713863 1875 1.495719884 1.451118772
2010 14 8813 730068 1850 1.223130217 1.207147827
2010 15 8801 749563 1831 1.177542409 1.174150805
2010 16 8362 719580 1765 1.091118514 1.162066761
2010 17 8440 720054 1755 1.119579371 1.172134312
2010 18 7914 705551 1710 1.08168512 1.121676534
2010 19 7697 669414 1664 1.124974827 1.149811626
2010 20 7603 670887 1624 1.06196979 1.133275798
2010 21 6853 633532 1497 1.089087669 1.081713315
2010 22 6595 549773 1421 1.17760142 1.199586011
2010 23 5755 604004 1435 0.974930395 0.95280826
2010 24 5316 580329 1405 0.98713178 0.916032113
2010 25 5334 575664 1384 0.995990538 0.926582173
2010 26 4718 542536 1347 0.904726272 0.869619712
2010 27 4691 519414 1353 0.941927008 0.903133146
2010 28 4234 547187 1284 0.880415229 0.773775693
2010 29 3950 531790 1265 0.842614662 0.742774403
2010 30 3850 526723 1250 0.858382365 0.730934476
2010 31 4077 518121 1241 0.833830395 0.786881829
2010 32 4008 525260 1212 0.847436543 0.76305068
2010 33 4518 537190 1225 0.888273269 0.841043206
2010 34 4420 558382 1235 0.765372288 0.791572794
2010 35 5007 548573 1170 0.918580443 0.91273176
2010 36 5493 531250 1198 1.014317872 1.033976471
2010 37 5510 589930 1210 1.012325612 0.93400912
2010 38 6741 623077 1206 1.118032817 1.081888755
2010 39 6387 599366 1254 1.118059422 1.065626011
2010 40 8473 746485 1838 1.109387134 1.135052948
2010 41 9347 746230 1875 1.243411499 1.252562883
2010 42 9684 777397 1907 1.257262029 1.245695571
2010 43 9904 781234 1929 1.257344775 1.267737963
2010 44 11020 766753 1947 1.434139584 1.43722946
2010 45 11807 769982 1940 1.518377991 1.533412469
2010 46 13336 787038 1921 1.616174081 1.694454397
2010 47 12079 606527 1938 1.843777191 1.991502439
2010 48 13997 772016 1964 1.725354397 1.813045325
2010 49 14958 742606 1936 1.879232217 2.014257897
2010 50 18022 704923 1916 2.337102955 2.556591287
2010 51 19899 588406 1840 3.035331428 3.381848588
2010 52 20346 592880 1887 3.135998856 3.431723114
2011 1 20026 744043 1923 2.533356137 2.691511109
2011 2 20721 711908 1921 2.912877126 2.910628901
2011 3 26257 751850 1964 3.444971016 3.492318947
2011 4 31975 798637 1947 4.161849768 4.003696298
2011 5 34284 772974 1970 4.551591511 4.435336764
2011 6 34456 812230 1961 4.465036621 4.24214816
2011 7 36567 831600 1910 4.551243251 4.397186147
2011 8 31277 801449 1908 4.082196881 3.902556495
2011 9 24627 781629 1860 3.38812252 3.150727519
2011 10 20377 747993 1829 2.991417579 2.724223355
2011 11 17309 741807 1823 2.615419081 2.33335625
2011 12 14031 728883 1790 2.090648213 1.925000309
2011 13 12957 739375 1770 1.861455225 1.752426036
2011 14 11498 729089 1723 1.613771334 1.577036548
2011 15 9391 691707 1681 1.421991745 1.35765577
2011 16 8695 662612 1651 1.338204589 1.312230989
2011 17 7830 681240 1612 1.199952655 1.14937467
2011 18 7307 655627 1585 1.148885988 1.114505656
2011 19 7236 651983 1556 1.121939541 1.109844889
2011 20 6530 620485 1516 1.0671236 1.052402556
2011 21 6072 586460 1381 1.050584728 1.035364731
2011 22 5946 531954 1357 1.152025575 1.117765822
2011 23 5547 564322 1296 0.970975002 0.982949451
2011 24 4989 539238 1279 0.894683261 0.925194441
2011 25 4448 532356 1251 0.843568301 0.835531111
2011 26 4218 506732 1225 0.815409145 0.832392665
2011 27 4009 468565 1211 0.823052353 0.855591007
2011 28 3721 526346 1220 0.674634799 0.706949421
2011 29 3597 518011 1203 0.631882795 0.694386799
2011 30 3538 514262 1179 0.641512538 0.687976168
2011 31 3202 496632 1175 0.529812879 0.644742989
2011 32 3523 521671 1175 0.644089346 0.675329853
2011 33 3874 531975 1191 0.66771825 0.72822971
2011 34 4444 551005 1195 0.705668092 0.806526257
2011 35 4717 548228 1200 0.804155047 0.860408443
2011 36 4813 514168 1184 0.907803772 0.936075368
2011 37 5567 575887 1196 1.005550427 0.9666827
2011 38 5822 584534 1201 1.036011298 0.996007076
2011 39 6708 605162 1213 1.07583254 1.108463519
2011 40 9365 778182 1850 1.160923985 1.203445981
2011 41 9803 791987 1883 1.197852415 1.237772842
2011 42 9958 794995 1905 1.279262601 1.252586494
2011 43 10298 788840 1900 1.291938615 1.305461184
2011 44 11396 784334 1925 1.428244468 1.452952441
2011 45 11496 797839 1946 1.398029384 1.44089221
2011 46 11721 801594 1900 1.458309829 1.462211543
2011 47 10377 626731 1918 1.565478899 1.655734278
2011 48 11479 782984 1904 1.343134813 1.466058055
2011 49 11187 736905 1898 1.481386467 1.518106133
2011 50 12137 729258 1872 1.633984564 1.664294392
2011 51 11958 645424 1851 1.831261781 1.852735566
2011 52 12356 581697 1821 2.104505893 2.124129916
2012 1 11992 678631 1891 1.736249461 1.767086974
2012 2 11543 747894 1883 1.550664054 1.543400535
2012 3 11939 724623 1887 1.628914741 1.647615381
2012 4 13209 784244 1891 1.760384475 1.684297234
2012 5 14448 775298 1885 1.927281921 1.863541503
2012 6 14624 784516 1875 1.919942436 1.864079254
2012 7 15929 789193 1884 2.099511932 2.018390939
2012 8 16137 767022 1853 2.239733513 2.103850998
2012 9 16518 788242 1826 2.219208332 2.095549336
2012 10 15763 749198 1816 2.1669258 2.103983193
2012 11 17150 747570 1819 2.389134426 2.294099549
2012 12 14524 755579 1780 1.964661774 1.922234472
2012 13 13017 747079 1753 1.842289327 1.742386013
2012 14 11930 711808 1729 1.686738579 1.676013757
2012 15 10732 717202 1707 1.531356691 1.496370618
2012 16 10123 732480 1699 1.379122383 1.382017256
2012 17 9370 726772 1675 1.295145862 1.289262657
2012 18 8999 662649 1564 1.395206744 1.358034193
2012 19 8576 655492 1546 1.325217612 1.308330231
2012 20 8062 636347 1503 1.230589531 1.266918835
2012 21 7878 616765 1415 1.230279678 1.277309834
2012 22 7153 550614 1409 1.268767813 1.299095192
2012 23 6765 581700 1365 1.107816068 1.162970603
2012 24 6133 564670 1289 1.095590381 1.086121097
2012 25 6048 572296 1295 1.110308286 1.056795784
2012 26 5786 536380 1260 1.106161219 1.078712853
2012 27 5291 505533 1271 1.108158905 1.046618124
2012 28 5185 558637 1240 0.999443977 0.928151913
2012 29 4931 546713 1223 0.924198584 0.901935751
2012 30 5103 557488 1250 0.949256676 0.915356026
2012 31 5159 541600 1240 0.978902812 0.952548006
2012 32 5026 548294 1248 0.925024122 0.916661499
2012 33 5051 560110 1238 0.848455695 0.901787149
2012 34 6141 594395 1238 1.04450505 1.033151356
2012 35 6318 600354 1238 1.098599787 1.052379096
2012 36 6296 558585 1242 1.220708068 1.12713374
2012 37 7382 622114 1252 1.249762568 1.186599241
2012 38 7656 630563 1268 1.228922639 1.214153066
2012 39 7807 623572 1248 1.293932615 1.251980525
2012 40 9395 779285 1932 1.23033799 1.205592306
2012 41 10158 769959 1940 1.327804131 1.319291027
2012 42 10585 797444 1968 1.339949599 1.327365934
2012 43 10913 798388 1958 1.378418572 1.366879262
2012 44 11061 734781 1929 1.500853 1.505346491
2012 45 12674 785871 1974 1.651627206 1.612732879
2012 46 13623 777534 1966 1.767460397 1.752077723
2012 47 14650 627772 1968 2.306093457 2.333649796
2012 48 18521 831670 2005 2.163524615 2.226965022
2012 49 24877 835762 2006 2.830381683 2.976565099
2012 50 29432 811800 1977 3.437605737 3.625523528
2012 51 34332 754019 1908 4.305536544 4.553200914
2012 52 36588 607171 1905 6.060823481 6.025979502
2013 1 34103 687051 1982 4.649307615 4.963678097
2013 2 39896 850531 1995 4.325837812 4.69071674
2013 3 39441 838326 2008 4.511125221 4.704733004
2013 4 32426 778610 1978 4.217104081 4.16460102
2013 5 29808 806640 1963 3.789557197 3.695328771
2013 6 24987 772086 1931 3.292056361 3.236297511
2013 7 22321 771229 1926 3.019702491 2.894211706
2013 8 20519 755092 1940 2.71499071 2.717417215
2013 9 19231 762238 1893 2.484501645 2.522965268
2013 10 18829 737736 1884 2.5780754 2.55226802
2013 11 17392 715059 1846 2.392373731 2.43224685
2013 12 15254 723449 1825 2.067784548 2.108510759
2013 13 13714 704276 1811 1.902809176 1.947247954
2013 14 12273 701881 1769 1.659022719 1.748587011
2013 15 10818 722583 1742 1.430057874 1.49712905
2013 16 9188 694415 1732 1.277570855 1.323128101
2013 17 8589 700300 1711 1.190089058 1.226474368
2013 18 7986 667648 1675 1.095563452 1.196139283
2013 19 7704 647130 1630 1.085889229 1.190487228
2013 20 7317 623114 1582 1.073427291 1.174263457
2013 21 6589 581338 1489 1.016768304 1.133419801
2013 22 6190 541528 1486 1.048469746 1.143061855
2013 23 5638 558875 1421 0.92034901 1.008812346
2013 24 5539 541138 1419 0.920779051 1.023583633
2013 25 5474 546643 1405 0.904333468 1.001384816
2013 26 4915 540408 1389 0.830570306 0.909498009
2013 27 4506 474295 1357 0.8628365 0.950041641
2013 28 4510 543833 1362 0.732182392 0.8292987
2013 29 4186 521874 1341 0.724557661 0.802109321
2013 30 4233 524969 1325 0.740847831 0.806333326
2013 31 3886 487617 1290 0.726037102 0.79693694
2013 32 4075 523015 1299 0.755638759 0.779136354
2013 33 4168 522533 1276 0.761846592 0.797652971
2013 34 4317 522965 1265 0.779895559 0.825485453
2013 35 5053 540157 1260 0.899137895 0.935468762
2013 36 5626 539175 1317 0.999523948 1.043446005
2013 37 6374 584196 1307 1.055801518 1.091072174
2013 38 7110 591969 1290 1.096701461 1.201076408
2013 39 7963 631088 1364 1.247092095 1.261789164
2013 40 9720 857840 2045 1.155048879 1.13307843
2013 41 10460 861819 2073 1.272561742 1.213711928
2013 42 10683 848493 2101 1.318516574 1.259055761
2013 43 12057 877466 2104 1.369358181 1.374070334
2013 44 12515 872861 2104 1.467579209 1.433790718
2013 45 13519 881000 2110 1.579542724 1.534506243
2013 46 13912 866594 2126 1.605219872 1.605365373
2013 47 15041 871054 2080 1.722214231 1.726758617
2013 48 13973 662397 2051 2.115783735 2.109460037
2013 49 18951 853863 2065 2.170548694 2.219442697
2013 50 19422 798360 2059 2.375538564 2.432737111
2013 51 24743 810406 2016 3.187326449 3.053161008
2013 52 26755 608539 2006 4.601250636 4.396595781
2014 1 28717 676955 2038 4.299873332 4.242084038
2014 2 28096 806876 2064 3.578460127 3.482071595
2014 3 28590 854988 2056 3.377921407 3.343906581
2014 4 25438 781475 2067 3.408356215 3.255126524
2014 5 23463 812308 2056 3.128145983 2.888436406
2014 6 21147 808721 2063 2.820804973 2.614869652
2014 7 18198 773128 2026 2.493493131 2.353814634
2014 8 17195 807603 2030 2.280405687 2.129140184
2014 9 15913 830404 1988 2.07586624 1.916296164
2014 10 15027 785260 1949 1.990388575 1.913633701
2014 11 13989 791666 1907 1.823958119 1.767033067
2014 12 14906 800364 1925 1.825338817 1.862402607
2014 13 14652 800461 1890 1.75902691 1.830445206
2014 14 14612 796356 1870 1.745988207 1.834857777
2014 15 14208 809589 1849 1.672844962 1.754964556
2014 16 11716 769718 1809 1.518148286 1.522115892
2014 17 10789 767568 1768 1.452091659 1.405608363
2014 18 9678 766422 1748 1.291751925 1.262750808
2014 19 9729 735060 1712 1.374845296 1.323565423
2014 20 9004 705320 1659 1.343895588 1.276583678
2014 21 8684 669716 1554 1.356666894 1.296669036
2014 22 7553 616865 1543 1.222918288 1.224417012
2014 23 7221 623568 1474 1.218015431 1.15801324
2014 24 6653 624705 1441 1.145238893 1.064982672
2014 25 6307 583756 1369 1.064175052 1.080417161
2014 26 5919 585161 1381 1.121190464 1.011516489
2014 27 5306 534110 1360 0.933654437 0.99342832
2014 28 5171 588825 1360 0.942301662 0.878189615
2014 29 5017 579453 1336 0.94484345 0.865816555
2014 30 4633 573056 1326 0.827265712 0.80847247
2014 31 4865 583432 1319 0.858936313 0.833858959
2014 32 4599 558470 1314 0.76132062 0.823499919
2014 33 4839 563391 1292 0.782279336 0.858906159
2014 34 5042 576346 1267 0.76755609 0.874821722
2014 35 5188 556797 1188 0.839570423 0.931757894
2014 36 4339 446380 944 0.881742274 0.972041758
<!DOCTYPE html>
<meta charset="utf-8">
<title>Rate by demographic</title>
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
svg {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.x.axis path {
fill:none;
stroke:#000;
shape-rendering: crispEdges;
}
.x.axis text {
font-size: 12px;
}
.line {
fill: none;
stroke-width: 1.5px;
}
</style>
<p id="hed"> <font size=6>Doctor visits for flu-like illness</font>
<p id="subhed"><font color="red" size=2>DRAFT not for publication or citation. Subject to revision</font>
<p id="questions" font size=2>Is this a proxy for flu severity each season? Why are the curves so different each season? What factors make one season more severe than another? Weather? Rain? Temperature? The particular mutation of the virus? </font><br><br>
_________________________________________________________________ Hover over a year to learn more <font size=6>↓</font>
<p id="chart">
<p id="footer">
Source: <a href="http://gis.cdc.gov/grasp/fluview/fluportaldashboard.html" target="_blank">http://gis.cdc.gov/grasp/fluview/fluportaldashboard.html Accessed 9/14/14</a>
<br><br>
Percentage of visits for influenza-like illness reported by the U.S. Outpatient Influenza-like Illness Surveillance Network (ILINet), weekly national summary, selected seasons
<br><br>
See more at CDC's <a href="http://www.cdc.gov/flu/weekly/" target=_blank>FluView</a>
<!-- ************* SOURCE & NOTES *************
http://gis.cdc.gov/grasp/fluview/fluportaldashboard.html Accessed 9/14/14
********* /SOURCE ******************** -->
<body>
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
console.log("ok");
//YEAR, WEEK, ILITOTAL, TOTAL PATIENTS, NUM OF PROVIDERS, PERCENT_WEIGHTED_ILI, PERCENT_UNWEIGHTED_ILI
var margin = {top: 20, right: 10, bottom: 40, left: 50},
width = 768 - margin.left - margin.right,
height = (width*0.66) - margin.top - margin.bottom;
var x = d3.scale.linear()
.range([0, width])
.domain([0, 52]);
var y = d3.scale.linear()
.range([height, 0])
.domain([0, 9]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var svg = d3.select("#chart").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 + ")");
var line = d3.svg.line()
.interpolate("basis")
.x(function (d) {return x(d.seasonal_week) ;})
.y(function (d) {return y(d.rate); })
var color = d3.scale.category10()
// ***** convert week enumeration into something we can use *******
// their data runs from week 35 of each year through about week 17 of the next.
// How to graph range = ([35, 17])?
// convert the first week in January to Week 53
// so range = ([35 - 83])
function seasonWeek(some_num) {
if (some_num < 30) {return some_num + 30;}
else {return some_num-30;}
;}
function seasonAssigner(num1, num2) {
// numb 1 is calendar week, num 2 is year
if (num1 < 30) {return (num2 -1) + " " + num2;}
else {return num2 + " " + (num2+1);}
;}
function classAssigner(some_str) { // alas you cant have numbers in a class name
if (some_str == "2007 2008") {return "zeroseven_zeroeight";}
if (some_str == "2008 2009") {return "zeroeight_zeronine";}
if (some_str == "2009 2010") {return "zeronine_ten";}
if (some_str == "2010 2011") {return "ten_eleven";}
if (some_str == "2011 2012") {return "eleven_twelve";}
if (some_str == "2012 2013") {return "twelve_thirteen";}
if (some_str == "2013 2014") {return "thirteen_fourteen";}
if (some_str == "2014 2015") {return "fourteen_fifteen";}
}
// ***** close week enumeration converter ********
// ********* LOAD DATA
//CATCHMENT, NETWORK, SEASON, MMWR-YEAR, MMWR-WEEK, AGE, CATEGORY, RATE
d3.csv("ILINet.csv", function (error, data){
console.log(data);
color.domain(d3.keys(data[0]).filter(function(key) {return key == 'YEAR'; }));
data.forEach(function (d) {
d.rate = +d.PERCENT_WEIGHTED_ILI,
d.calendar_week = +d.WEEK,
d.seasonal_week = seasonWeek(+d.WEEK),
d.year = +d.YEAR,
d.season = seasonAssigner(d.calendar_week, d.year);
});
console.log(data);
data = d3.nest().key(function (d) {return d.season; }).entries(data);
console.log(data);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("y", 30)
.text("Week 0 = first week in September");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0-margin.left)
.attr("x", 0-height/2)
.attr("dy", "1em")
.style("text-anchor", "middle")
.text("percent of visits for influenza-like symptoms")
var seasons = svg.selectAll(".season")
.data(data, function (d) {return d.key; })
.enter().append("g")
.attr('class', function (d) {return classAssigner(d.key) + " line"; });
seasons.append("path")
.attr("class", "line")
.attr("d", function (d) {return line(d.values); })
.style("stroke", function (d) {return color(d.key); });
var legend = svg.selectAll('.legend')
.data(data, function (d) {return d.key;})
.enter()
.append('g')
.attr('class', function (d) {return classAssigner(d.key) + " legend"; });
legend.append('rect')
.attr('x', width - 60)
.attr('y', function(d, i){ return i * 20;})
.attr('width', 18)
.attr('height', 18)
.style('fill', function(d) {return color(d.key); });
legend.append('text')
.attr('x', width - 40)
.attr('y', function(d, i){ return (i * 20) + 9;})
.text(function(d){ return d.key; })
.on("mouseover", function (d){
d3.selectAll("." + classAssigner(d.key) + " .line").style("stroke", "black").style("stroke-width", "5px")
})
.on("mouseout", function (d) {
d3.selectAll("." + classAssigner(d.key) + " .line").style("stroke", function (k) {return color(k.key)}).style("stroke-width", "1.5px")
})
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment