Skip to content

Instantly share code, notes, and snippets.

@dropofwill
Last active August 29, 2015 14:06
Show Gist options
  • Save dropofwill/961ba875ee2a8c8c8dd7 to your computer and use it in GitHub Desktop.
Save dropofwill/961ba875ee2a8c8c8dd7 to your computer and use it in GitHub Desktop.
US Home Value Index

This chart uses data from Zillow Real Estate Research that combines data on home valuations and sales to get an accurate view of housing cost overtime. In this particular example I'm visualizing the top 10 most populated metro areas and the United States average.

The data from Zillow had the dates as columns, this made creating the D3 data objects a little bit more awkward than I wanted to deal with, so I wrote a simple ruby script to transpose the data to a more convenient form. I've included the original, transposed, and script for posterities sake.

Default label is on the United States average, hover over the other lines to see what cities they represent.

  • d3.csv to parse the data
  • d3.time.format to parse dates
  • d3.time.scale for the x-axis
  • d3.scale.linear for the y-axis
  • d3.scale.category10 to generate the colors
  • d3.extent, d3.min, and d3.max to compute the relevant domains
  • d3.svg.axis to render the axes
  • d3.svg.line to render the lines

Some interesting aspects of the data was just how expensive California is, even compared to places like DC and NYC. Also it's interesting to see which cities were most effected by the current spike and the one around 2006.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font-family: "verdana", sans-serif;
}
.hide {
display: none;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.line {
fill: none;
stroke-width: 3px;
}
.off-line {
opacity: 0.4;
}
</style>
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="reusableChart.js"></script>
<div class="graph-wrapper">
</div>
</body>
</html>
RegionName 1996-04 1996-05 1996-06 1996-07 1996-08 1996-09 1996-10 1996-11 1996-12 1997-01 1997-02 1997-03 1997-04 1997-05 1997-06 1997-07 1997-08 1997-09 1997-10 1997-11 1997-12 1998-01 1998-02 1998-03 1998-04 1998-05 1998-06 1998-07 1998-08 1998-09 1998-10 1998-11 1998-12 1999-01 1999-02 1999-03 1999-04 1999-05 1999-06 1999-07 1999-08 1999-09 1999-10 1999-11 1999-12 2000-01 2000-02 2000-03 2000-04 2000-05 2000-06 2000-07 2000-08 2000-09 2000-10 2000-11 2000-12 2001-01 2001-02 2001-03 2001-04 2001-05 2001-06 2001-07 2001-08 2001-09 2001-10 2001-11 2001-12 2002-01 2002-02 2002-03 2002-04 2002-05 2002-06 2002-07 2002-08 2002-09 2002-10 2002-11 2002-12 2003-01 2003-02 2003-03 2003-04 2003-05 2003-06 2003-07 2003-08 2003-09 2003-10 2003-11 2003-12 2004-01 2004-02 2004-03 2004-04 2004-05 2004-06 2004-07 2004-08 2004-09 2004-10 2004-11 2004-12 2005-01 2005-02 2005-03 2005-04 2005-05 2005-06 2005-07 2005-08 2005-09 2005-10 2005-11 2005-12 2006-01 2006-02 2006-03 2006-04 2006-05 2006-06 2006-07 2006-08 2006-09 2006-10 2006-11 2006-12 2007-01 2007-02 2007-03 2007-04 2007-05 2007-06 2007-07 2007-08 2007-09 2007-10 2007-11 2007-12 2008-01 2008-02 2008-03 2008-04 2008-05 2008-06 2008-07 2008-08 2008-09 2008-10 2008-11 2008-12 2009-01 2009-02 2009-03 2009-04 2009-05 2009-06 2009-07 2009-08 2009-09 2009-10 2009-11 2009-12 2010-01 2010-02 2010-03 2010-04 2010-05 2010-06 2010-07 2010-08 2010-09 2010-10 2010-11 2010-12 2011-01 2011-02 2011-03 2011-04 2011-05 2011-06 2011-07 2011-08 2011-09 2011-10 2011-11 2011-12 2012-01 2012-02 2012-03 2012-04 2012-05 2012-06 2012-07 2012-08 2012-09 2012-10 2012-11 2012-12 2013-01 2013-02 2013-03 2013-04 2013-05 2013-06 2013-07 2013-08 2013-09 2013-10 2013-11 2013-12 2014-01 2014-02 2014-03 2014-04 2014-05 2014-06 2014-07
United States 100500 100900 101200 101200 101100 100800 101100 101600 102100 102600 102900 103200 103600 103800 104000 104300 104700 105100 105600 106200 106600 106700 107200 107800 107900 108000 108800 109800 110600 111000 111400 111600 112100 112700 113300 114000 114700 115400 116000 116500 117000 117600 118100 118600 119100 119700 120500 121500 122400 123000 123300 123700 124400 125200 125900 126600 127300 128100 128800 129200 129800 130500 131200 131700 132300 132700 133200 133700 134300 134900 135500 135800 136300 137200 138000 138700 139700 140700 141600 142600 143200 143700 144300 145100 145800 146700 147800 148900 149900 151000 152200 153400 154600 155800 157000 158500 160000 161200 162400 163700 164900 166100 167300 168600 170300 172400 174200 175700 177100 178400 180200 182200 184100 185700 187200 188800 190000 190900 191500 192400 193200 193900 194300 194400 194500 195100 195500 195700 195800 195900 196300 196700 196500 195800 195200 194800 194500 193600 192400 191500 190200 188400 186800 185700 184400 183300 182200 181200 180000 178500 176500 174100 173500 174100 174000 172700 171700 171100 170900 170300 169600 169200 169300 169200 168300 167500 167100 166600 166200 165600 164300 162700 161700 161300 160900 160200 159200 158200 157400 156700 156300 155800 155100 154700 154200 153400 152800 153000 152700 152000 151700 152100 152400 152800 153300 153800 154200 154900 155800 156700 157200 157700 158500 159500 160400 161300 162700 164100 164800 165500 166300 167400 168600 169300 169800 170500 171900 173400 174500 174800
New York, NY 168500 169100 169200 168600 168100 167700 166800 165400 164400 164600 165600 166500 166900 167200 167400 167700 168200 168700 169200 169900 170500 171600 173000 174200 174800 175200 175700 176400 177000 177500 178400 179800 181000 182300 183900 185400 186600 188400 190400 192200 194000 195800 197400 199500 202400 205400 207900 209800 211300 213200 215600 218000 220300 223000 225700 228100 229900 232200 235000 237500 239700 242000 244000 246400 249200 252300 255500 258500 261400 262800 263700 266000 270200 274000 277600 281500 285900 289800 293400 297300 301000 304600 308700 313100 316300 319500 323700 327900 330800 333400 336000 338700 343000 348300 352600 355300 358700 362400 365900 369700 374300 379000 383600 388400 392700 397000 401800 407200 412200 416600 420700 424700 428400 432000 435600 438700 441300 443500 445500 447200 448800 449900 450700 451100 451200 451000 450400 449600 448400 447300 446600 446100 445400 444600 443100 441000 439000 437500 436200 434900 433200 431500 429200 425800 421800 417800 413900 410800 408400 405800 402600 398800 395800 394000 392200 389000 385600 382100 379300 377500 376700 376700 376900 377000 377000 376800 376500 376500 376900 377100 376700 375600 373800 371900 370600 370000 368400 365800 364300 363600 362400 361800 362200 361000 358600 356700 354700 352400 350300 348200 346500 346900 347200 347400 347900 348800 347700 346200 345400 346400 346600 346200 347100 349300 351300 354400 357500 360400 362500 363700 364700 366200 367900 369300 369700 368400 371300 374600 375300 374700
Los Angeles, CA 172700 172800 172700 172500 172300 172200 172500 172900 173400 174200 175200 175700 175900 176100 176400 176800 177300 178000 178900 180100 181600 183500 185300 187200 189000 190400 191800 193400 195300 197400 199400 201500 203200 204800 206700 208500 209900 211200 213100 214800 215900 217000 218500 220300 222400 224900 227600 229900 231900 234200 236200 238000 239900 241900 243800 245700 248000 250500 253100 255700 258000 260100 262200 264400 266800 269200 271600 274100 276900 280200 283600 287000 291100 296000 300600 305500 311100 316900 322400 328200 333800 339300 344500 349700 354600 359100 363500 368600 374600 381100 388300 396200 404500 412600 421200 430900 441700 453600 466300 477700 487200 495000 501400 506800 511800 516700 522200 529000 536700 544300 552100 560800 569800 578300 586100 593300 599400 604200 607400 609800 611200 612600 613900 614100 613000 611700 610600 608300 605200 603500 602600 600000 596700 593200 588500 583200 577900 571700 565900 559700 552300 544200 535300 524400 512300 501100 491500 482500 473700 465900 459500 453800 449700 446400 442000 437400 434100 431400 430000 430000 430600 431300 432200 433400 434800 434800 435900 438200 439300 438000 436300 433500 431200 428300 425200 422400 420300 418200 417200 416200 414600 412500 410100 407600 405100 402900 401200 399700 397600 396200 395600 396600 399200 402200 403900 405800 408700 412600 416900 421100 426500 433800 441000 447100 454700 464600 473600 479200 482800 486900 490900 496000 500600 504500 508600 515600 521100 524000 526300 529200
Dallas-Fort Worth, TX 100300 100400 100400 100600 100900 101000 101000 98600 95300 94200 95100 95400 95600 95600 95800 96100 96500 96900 97300 97900 98700 99500 100000 100300 100400 100300 100400 100600 100900 101000 101300 101900 102800 103500 103900 104500 105200 106000 106800 107700 108400 109100 109800 111000 112100 112600 113000 113300 113400 113900 114200 114200 114500 115000 115400 116000 116800 117400 117900 118300 118700 119300 119800 120000 120200 120600 121100 121600 122200 122700 122900 123200 123600 123900 124200 124700 125100 125400 125700 126100 126600 127100 127400 127700 128000 128100 128200 128200 128300 128600 128800 128900 129200 129900 131000 132100 133100 134100 135200 136300 137100 137700 138100 138300 138600 139000 139400 139800 140200 140700 140900 140800 140800 140900 141200 141600 142000 142400 142900 143200 143400 143700 144100 144400 144700 144900 145100 145500 145800 146100 146300 146500 146700 146900 147100 147400 147700 148000 148400 148700 148600 147700 146300 144900 143800 142700 141600 140900 140500 140100 139500 138700 137700 136700 135800 135000 134300 133700 133100 132900 132800 132800 132800 132700 132300 132300 132800 132900 132500 132100 132000 131700 131100 130500 130100 129700 129400 129100 129000 128900 128900 128700 128300 127800 127500 127000 126600 126700 126800 126800 127000 127300 127600 128000 128400 128700 128900 129100 129500 130200 130900 131700 132500 133600 134700 135800 136900 138100 139100 139900 140500 140600 141200 142000 142600 143000 143900 145200 146300 147100
Philadelphia, PA 107000 107200 107500 107600 107500 107400 107300 107200 107100 107200 107500 107700 107500 107400 107100 107100 107100 107000 107000 107100 107400 108100 108800 109200 109500 109700 109700 109600 109700 109800 110100 110500 111000 111500 112200 112800 113100 113500 114000 114400 114700 115300 115900 116200 116300 116700 117400 118000 118600 119100 119500 120000 120700 121400 122000 122800 123600 124200 124700 125400 126300 127200 128000 128900 129900 130600 131400 132300 133400 134500 135700 136800 137900 139100 140400 141800 143200 144800 146300 147900 149800 151400 152900 154500 156100 157600 159300 161100 162800 164600 166500 168400 170000 171600 173300 175000 176800 179000 181200 183700 186200 188800 191100 193400 195900 198500 200900 203100 205400 207700 210300 213000 215400 217600 219700 221700 223700 225100 226200 227200 228400 229300 230100 230700 231000 231100 231200 231000 230800 231100 231500 231600 231400 231300 231100 230900 230600 230200 229600 228700 228300 227900 226900 225400 224200 222900 222100 221600 221000 220100 219200 218200 217800 218000 217900 216900 215400 213800 212900 212400 212400 212600 212800 213400 212300 211000 211200 212800 212900 212400 210100 207800 206400 206200 205400 204300 203000 201500 200000 198600 198100 197900 197700 197100 196300 194700 193100 191700 190800 190000 189300 189300 189200 189000 189400 189700 188600 187600 187600 187900 188000 187500 187700 188600 189700 190900 192400 192900 192700 192500 192600 193000 193500 194100 194400 194300 196600 199400 199900 199200
Washington, DC 157300 157400 157400 157200 156800 156500 156400 156300 156300 156700 157100 157300 157200 155900 154000 153000 152900 153100 153300 153600 154000 154900 155700 156200 156400 156700 156900 157200 157300 157500 158000 158500 158900 159500 160500 161300 161700 162300 163400 164600 165600 166400 167000 167800 169000 170300 171500 172400 173300 174800 176400 177700 178700 179900 181400 183100 185000 187000 189100 191400 193600 195700 198100 200700 203100 205500 207900 210000 212100 214600 217300 220000 223000 226300 229600 232700 236100 239600 243100 246600 250300 253600 256800 259800 262600 265300 268400 271600 274900 278300 282000 286000 290100 294500 299300 304700 310700 316800 323000 329800 337100 344400 351300 358000 364700 371100 377100 383300 390200 397100 403900 410300 415800 420100 423600 426800 429200 430800 431300 431300 431100 430600 429300 427400 425200 423100 420900 418800 416900 415300 414200 413000 411400 409600 407200 404500 401500 398300 394700 390800 386600 381700 375600 369100 363200 357800 352900 348700 345000 341500 337800 333500 330000 327700 325300 322400 319900 317700 316100 315300 314800 314600 314800 315400 315700 316000 316900 318000 317800 316300 314600 313300 311900 310600 309700 309400 309300 308800 308800 308800 308000 307600 307600 306900 306600 306200 305900 306300 306400 306200 307100 308800 310300 311300 311800 312100 311900 311900 313200 314200 314600 316400 319700 323100 327200 331100 334400 337100 339100 341100 342600 344100 346100 347600 348600 349400 351800 355800 358800 359900
Miami-Fort Lauderdale, FL 95300 95300 95300 95200 95100 95200 95200 95300 95800 96300 96600 97000 97400 97600 97700 98000 98700 99000 99000 99000 99200 99700 100300 100600 100900 101300 101400 101400 101600 101900 102100 102600 103100 103500 104100 104800 105100 105500 106100 106700 107000 107400 107900 108500 109200 110000 110700 111500 112200 113200 114300 115400 116100 116800 117600 118500 119400 120400 121600 122800 124100 125500 127000 128400 129700 131200 133100 134700 136300 138100 139800 141200 142600 143900 145400 147200 149300 151500 153600 155600 157600 159500 161300 163300 165300 167200 169100 170900 172900 175000 177300 179500 181900 184700 187800 191000 194700 198900 203200 207500 212400 217200 222100 227200 232500 237800 243700 249900 256600 263300 270200 277300 283800 289400 294500 299100 302400 304600 306900 309300 311100 312100 312400 312000 311200 310000 308900 307700 305900 304400 302900 300600 297600 294000 290200 286500 282600 278200 273600 269400 264700 259300 253200 246700 239900 233600 227600 222000 216000 209500 203000 196700 191500 187800 184100 179500 174900 171100 168300 166000 164100 162800 161900 161000 162000 162600 161300 159500 158900 158100 156400 154400 152800 151600 150600 150300 148500 146100 144800 145400 145700 145300 145000 144900 144700 144800 144700 144400 144300 144700 146000 147700 148900 150200 151800 152300 153400 154900 156500 157600 158900 160400 162300 164100 166100 168400 170900 173800 175700 178000 180500 183100 185300 186900 188600 190700 193900 197300 200000 201300
Atlanta, GA 108400 108600 108500 108500 108400 108400 108600 108900 109200 109500 109900 110200 110500 111000 111600 112200 112800 113500 114000 114500 115000 115600 116500 117300 117800 118200 118800 119400 120100 120800 121500 122200 123000 124000 124800 125500 126200 127000 128100 129100 129900 130600 131400 132400 133100 133900 134900 135900 136700 137600 138400 139200 139900 140400 141100 141900 142500 143000 143800 144500 145100 145500 146200 146800 147300 147900 148400 148700 149100 149800 150200 150500 151000 151600 151900 152400 152900 153200 153500 153900 154200 154600 155000 155300 155600 156000 156200 156300 156600 157000 157400 157900 158400 158700 159100 159500 159800 160000 160400 160800 161200 161700 162200 162600 163100 163700 164400 164900 165400 166000 166500 166900 167600 168400 169100 169800 170400 170900 171500 171900 172400 172800 173400 174000 174500 174600 174700 174900 174700 173900 173100 172900 173000 173100 173000 172900 173100 173000 172600 172000 171100 170200 169400 168400 166900 165200 163800 162700 161000 158800 156600 154000 151700 150800 150400 149200 147500 146200 145500 145100 144800 144400 144000 143500 144900 146200 145300 143200 143100 142600 141100 139100 137200 135700 134800 134200 132700 131400 130600 130000 128800 127800 127000 125800 124300 123400 122900 122700 122100 120200 119100 119900 120500 120400 120700 120300 120100 120600 120700 120200 120400 121500 122600 123300 124200 125700 127000 128900 130900 132400 134300 136800 138000 138400 139400 141400 143600 145300 146800 148100
Boston, MA 152600 152700 152800 152900 153000 153200 153400 153900 154600 155600 156800 157800 158600 159300 160100 160900 161700 162600 163600 164900 166400 168100 169800 171300 172700 174100 175300 176400 177700 179200 180700 182000 183400 184900 186500 188300 190300 192500 194800 197500 200100 202600 205100 207900 210400 212900 215700 218700 221600 224800 228600 232400 236000 239200 242100 245000 248200 251700 254900 257900 260900 263800 266600 269500 272400 275500 278700 281300 283100 285000 287400 289900 292200 294900 297800 300900 304000 307300 310600 313900 317400 320800 323500 325600 327400 329100 331000 332800 334300 335800 337600 340000 342400 344600 347200 350300 353400 356400 359100 361400 363900 366300 368500 370700 372900 375100 377300 379300 381200 382800 383700 384100 384400 384700 384600 383800 382800 381800 380500 379100 377900 375900 373300 371100 369000 366500 364100 362500 361300 360400 359700 358900 357800 356700 355400 354000 352700 351400 349900 348500 347300 346100 343800 339800 335800 333300 331900 331000 330300 329100 327600 325700 324100 323000 321300 318500 316500 316100 316700 317900 319600 320900 321700 323000 322700 321300 321800 325100 326400 325400 324100 322700 321000 319500 318500 317600 317800 317000 315200 314700 315600 316400 316600 315500 313600 312800 312300 311600 310700 310900 311500 312700 314400 315800 316600 317500 317800 318400 320200 322300 323400 324700 326900 329600 332700 336300 339100 341400 343300 344900 346400 347400 348300 350000 353500 356600 359800 361700 362500 362300
San Francisco, CA 226200 227100 227100 226200 225900 226100 226300 226600 227500 229100 230700 232100 233600 235300 236800 238300 240100 242100 244600 247300 250200 253600 257000 260100 259800 257400 259800 266300 270300 272200 274800 277400 280300 283200 285400 287000 289700 294300 299100 303900 309300 315200 321400 327900 334100 341000 348900 356600 365000 374200 382300 388400 394500 400500 406300 412300 417900 422400 426700 430500 432800 433100 431700 430000 429100 429100 428900 428600 428400 428900 430400 433100 437000 443000 449600 456000 461700 466100 469200 471700 473700 475600 477700 479900 482200 484600 486900 489400 493500 498900 505100 512000 519900 527800 535400 543300 552400 561300 569500 578000 586300 594900 604200 614400 625200 636400 647200 657700 667100 675100 682500 689400 695200 699800 703000 705300 707400 708400 707500 705300 703400 701700 699700 697400 695300 693200 691400 689400 687200 685800 684900 684400 684000 683400 682200 681100 679200 675900 670400 664000 657000 648400 637500 626300 616700 607900 598900 590300 581000 571300 562700 555000 549800 546000 539800 531500 524900 520700 519100 519300 520500 521400 522300 525600 525500 525700 530000 532100 529100 527900 526100 521400 518300 516600 514800 510500 507500 503500 499400 497600 497600 494400 491000 488900 487400 484700 482800 482400 481000 477900 477900 481800 486200 491500 497300 503300 507700 514200 522300 529800 535300 544100 557600 573200 589400 602900 612700 617300 621900 628300 635000 638900 644700 653500 662100 671200 677000 679700 683200 688600
Riverside, CA 112600 112500 112200 112300 112500 112400 112300 112300 112400 113100 114000 114400 114700 115000 115400 115800 116100 116300 116600 117100 117700 118500 119600 120400 120700 121200 121800 122300 122700 123200 124200 125000 125600 126200 127000 127600 128400 129300 130300 131100 132000 133100 133900 134900 136300 137700 139100 140600 141800 142700 143500 144400 145500 146700 147500 148500 149900 151200 152300 153800 155700 157800 159600 161100 162400 163700 165100 166500 168000 169800 171900 173800 175600 177500 179600 181900 184400 186900 189600 192300 194900 197700 200600 203400 206600 209900 213300 216900 220600 225200 230900 237400 243700 249500 255500 262300 269600 277400 285700 294000 302200 309500 315900 321500 326400 331200 336000 340900 345700 350700 356000 361600 366900 372200 377800 383300 388000 392100 395500 398500 400800 402300 402700 402500 402100 401400 399400 396300 393000 390200 387500 384800 382100 378900 374900 370400 365600 360400 354700 348300 341400 335000 328100 319600 310400 301400 292200 283800 275600 267300 259200 251600 244900 239200 233200 227400 222500 218100 214400 211600 208800 206600 205400 205000 205400 206300 207100 206600 205700 204700 203400 201900 201700 201100 199700 198700 197700 196100 195300 195000 194100 193500 193400 192600 191300 190000 189200 189100 188900 187700 187300 188400 190100 191000 192400 194200 195300 196800 199300 201800 204500 208100 211900 215800 220400 226100 232500 237900 242500 246700 250400 253900 256600 258700 260600 264300 268600 272500 275100 277100
var parseDate = d3.time.format("%Y-%m").parse,
// Create margins to draw the axes in
margin = {top: 20, right: 150, bottom: 30, left: 100},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom,
svg,
x,
y,
color,
xAxis,
yAxis,
line,
xAxisG,
yAxisG,
regionsG ;
svg = d3.select("body")
.append("svg")
.attr("width", 960)
.attr("height", 500)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
;
x = d3.time.scale()
.range([0, width])
;
y = d3.scale.linear()
.range([height, 0])
;
color = d3.scale.category10();
xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
;
yAxis = d3.svg.axis()
.scale(y)
.orient("left")
;
line = d3.svg.line()
.interpolate("basis")
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.cost); })
;
// Load the converted csv
d3.csv("./transposed_home_cost.csv", function(err, data) {
var colorDomain,
regions;
// Grab title row of the csv and only create a color
// for ones that are regions, e.g not the dates
colorDomain = d3.keys(data[0])
.filter(function(key) { return key !== "Date"; })
;
color.domain(colorDomain);
// Parse that date strings
data.forEach(function(row) {
row.Date = parseDate(row.Date);
});
// Build a nested object with the data
// First of each region
// Then cost at a particular date
regions = color.domain().map(function(region) {
return {
region: region,
values: data.map(function(d) {
return {
date: d.Date,
cost: +d[region]
};
})
};
});
x.domain(d3.extent(data, function(d) { return d.Date; }));
y.domain([
d3.min(regions, function(r) {
var regionalMin = d3.min(r.values, function(v) { return v.cost; } );
return regionalMin;
}),
d3.max(regions, function(r) {
var regionalMax = d3.max(r.values, function(v) { return v.cost; } );
return regionalMax;
})
]);
xAxisG = svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
;
yAxisG = svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("y", 6)
.attr("dy", "0.71em")
.style("text-anchor", "end")
;
regionsG = svg.selectAll(".region")
.data(regions)
.enter()
.append("g")
.attr("class", "region");
regionsG.append("path")
.attr("class", "line")
.attr("d", function(d) { return line(d.values); })
.style("stroke", function(d) { return color(d.region); });
regionsG.append("text")
.datum(function(d) {
console.log(d);
return {
region: d.region,
value: d.values[d.values.length - 1]
};
})
.attr("transform", function(d) {
console.log();
return "translate(" + x(d.value.date) + "," + y(d.value.cost) + ")";
})
.attr("x", 3)
.attr("dy", ".35em")
.attr("class", "text-labels")
.classed("hide", function(d) { if (d.region != "United States") return true; } )
.text(function(d) { return d.region; })
;
d3.selectAll(".line")
.on("mouseover", function(d) {
console.log(this);
d3.selectAll(".line")
.classed("off-line", function(lineData) {
if (lineData.region != d.region)
return true;
})
;
d3.selectAll(".text-labels")
.classed("hide", function(labelData) {
if (labelData.region != d.region)
return true;
})
;
});
});
require "csv"
require "pp"
data = []
CSV.foreach("original_home_cost.csv") do |row|
data << row
end
#pp data
data = data.transpose
CSV.open("transposed_home_cost.csv", "wb") do |csv|
data.each do |row|
csv << row
end
end
Date United States New York, NY Los Angeles, CA Dallas-Fort Worth, TX Philadelphia, PA Washington, DC Miami-Fort Lauderdale, FL Atlanta, GA Boston, MA San Francisco, CA Riverside, CA
1996-04 100500 168500 172700 100300 107000 157300 95300 108400 152600 226200 112600
1996-05 100900 169100 172800 100400 107200 157400 95300 108600 152700 227100 112500
1996-06 101200 169200 172700 100400 107500 157400 95300 108500 152800 227100 112200
1996-07 101200 168600 172500 100600 107600 157200 95200 108500 152900 226200 112300
1996-08 101100 168100 172300 100900 107500 156800 95100 108400 153000 225900 112500
1996-09 100800 167700 172200 101000 107400 156500 95200 108400 153200 226100 112400
1996-10 101100 166800 172500 101000 107300 156400 95200 108600 153400 226300 112300
1996-11 101600 165400 172900 98600 107200 156300 95300 108900 153900 226600 112300
1996-12 102100 164400 173400 95300 107100 156300 95800 109200 154600 227500 112400
1997-01 102600 164600 174200 94200 107200 156700 96300 109500 155600 229100 113100
1997-02 102900 165600 175200 95100 107500 157100 96600 109900 156800 230700 114000
1997-03 103200 166500 175700 95400 107700 157300 97000 110200 157800 232100 114400
1997-04 103600 166900 175900 95600 107500 157200 97400 110500 158600 233600 114700
1997-05 103800 167200 176100 95600 107400 155900 97600 111000 159300 235300 115000
1997-06 104000 167400 176400 95800 107100 154000 97700 111600 160100 236800 115400
1997-07 104300 167700 176800 96100 107100 153000 98000 112200 160900 238300 115800
1997-08 104700 168200 177300 96500 107100 152900 98700 112800 161700 240100 116100
1997-09 105100 168700 178000 96900 107000 153100 99000 113500 162600 242100 116300
1997-10 105600 169200 178900 97300 107000 153300 99000 114000 163600 244600 116600
1997-11 106200 169900 180100 97900 107100 153600 99000 114500 164900 247300 117100
1997-12 106600 170500 181600 98700 107400 154000 99200 115000 166400 250200 117700
1998-01 106700 171600 183500 99500 108100 154900 99700 115600 168100 253600 118500
1998-02 107200 173000 185300 100000 108800 155700 100300 116500 169800 257000 119600
1998-03 107800 174200 187200 100300 109200 156200 100600 117300 171300 260100 120400
1998-04 107900 174800 189000 100400 109500 156400 100900 117800 172700 259800 120700
1998-05 108000 175200 190400 100300 109700 156700 101300 118200 174100 257400 121200
1998-06 108800 175700 191800 100400 109700 156900 101400 118800 175300 259800 121800
1998-07 109800 176400 193400 100600 109600 157200 101400 119400 176400 266300 122300
1998-08 110600 177000 195300 100900 109700 157300 101600 120100 177700 270300 122700
1998-09 111000 177500 197400 101000 109800 157500 101900 120800 179200 272200 123200
1998-10 111400 178400 199400 101300 110100 158000 102100 121500 180700 274800 124200
1998-11 111600 179800 201500 101900 110500 158500 102600 122200 182000 277400 125000
1998-12 112100 181000 203200 102800 111000 158900 103100 123000 183400 280300 125600
1999-01 112700 182300 204800 103500 111500 159500 103500 124000 184900 283200 126200
1999-02 113300 183900 206700 103900 112200 160500 104100 124800 186500 285400 127000
1999-03 114000 185400 208500 104500 112800 161300 104800 125500 188300 287000 127600
1999-04 114700 186600 209900 105200 113100 161700 105100 126200 190300 289700 128400
1999-05 115400 188400 211200 106000 113500 162300 105500 127000 192500 294300 129300
1999-06 116000 190400 213100 106800 114000 163400 106100 128100 194800 299100 130300
1999-07 116500 192200 214800 107700 114400 164600 106700 129100 197500 303900 131100
1999-08 117000 194000 215900 108400 114700 165600 107000 129900 200100 309300 132000
1999-09 117600 195800 217000 109100 115300 166400 107400 130600 202600 315200 133100
1999-10 118100 197400 218500 109800 115900 167000 107900 131400 205100 321400 133900
1999-11 118600 199500 220300 111000 116200 167800 108500 132400 207900 327900 134900
1999-12 119100 202400 222400 112100 116300 169000 109200 133100 210400 334100 136300
2000-01 119700 205400 224900 112600 116700 170300 110000 133900 212900 341000 137700
2000-02 120500 207900 227600 113000 117400 171500 110700 134900 215700 348900 139100
2000-03 121500 209800 229900 113300 118000 172400 111500 135900 218700 356600 140600
2000-04 122400 211300 231900 113400 118600 173300 112200 136700 221600 365000 141800
2000-05 123000 213200 234200 113900 119100 174800 113200 137600 224800 374200 142700
2000-06 123300 215600 236200 114200 119500 176400 114300 138400 228600 382300 143500
2000-07 123700 218000 238000 114200 120000 177700 115400 139200 232400 388400 144400
2000-08 124400 220300 239900 114500 120700 178700 116100 139900 236000 394500 145500
2000-09 125200 223000 241900 115000 121400 179900 116800 140400 239200 400500 146700
2000-10 125900 225700 243800 115400 122000 181400 117600 141100 242100 406300 147500
2000-11 126600 228100 245700 116000 122800 183100 118500 141900 245000 412300 148500
2000-12 127300 229900 248000 116800 123600 185000 119400 142500 248200 417900 149900
2001-01 128100 232200 250500 117400 124200 187000 120400 143000 251700 422400 151200
2001-02 128800 235000 253100 117900 124700 189100 121600 143800 254900 426700 152300
2001-03 129200 237500 255700 118300 125400 191400 122800 144500 257900 430500 153800
2001-04 129800 239700 258000 118700 126300 193600 124100 145100 260900 432800 155700
2001-05 130500 242000 260100 119300 127200 195700 125500 145500 263800 433100 157800
2001-06 131200 244000 262200 119800 128000 198100 127000 146200 266600 431700 159600
2001-07 131700 246400 264400 120000 128900 200700 128400 146800 269500 430000 161100
2001-08 132300 249200 266800 120200 129900 203100 129700 147300 272400 429100 162400
2001-09 132700 252300 269200 120600 130600 205500 131200 147900 275500 429100 163700
2001-10 133200 255500 271600 121100 131400 207900 133100 148400 278700 428900 165100
2001-11 133700 258500 274100 121600 132300 210000 134700 148700 281300 428600 166500
2001-12 134300 261400 276900 122200 133400 212100 136300 149100 283100 428400 168000
2002-01 134900 262800 280200 122700 134500 214600 138100 149800 285000 428900 169800
2002-02 135500 263700 283600 122900 135700 217300 139800 150200 287400 430400 171900
2002-03 135800 266000 287000 123200 136800 220000 141200 150500 289900 433100 173800
2002-04 136300 270200 291100 123600 137900 223000 142600 151000 292200 437000 175600
2002-05 137200 274000 296000 123900 139100 226300 143900 151600 294900 443000 177500
2002-06 138000 277600 300600 124200 140400 229600 145400 151900 297800 449600 179600
2002-07 138700 281500 305500 124700 141800 232700 147200 152400 300900 456000 181900
2002-08 139700 285900 311100 125100 143200 236100 149300 152900 304000 461700 184400
2002-09 140700 289800 316900 125400 144800 239600 151500 153200 307300 466100 186900
2002-10 141600 293400 322400 125700 146300 243100 153600 153500 310600 469200 189600
2002-11 142600 297300 328200 126100 147900 246600 155600 153900 313900 471700 192300
2002-12 143200 301000 333800 126600 149800 250300 157600 154200 317400 473700 194900
2003-01 143700 304600 339300 127100 151400 253600 159500 154600 320800 475600 197700
2003-02 144300 308700 344500 127400 152900 256800 161300 155000 323500 477700 200600
2003-03 145100 313100 349700 127700 154500 259800 163300 155300 325600 479900 203400
2003-04 145800 316300 354600 128000 156100 262600 165300 155600 327400 482200 206600
2003-05 146700 319500 359100 128100 157600 265300 167200 156000 329100 484600 209900
2003-06 147800 323700 363500 128200 159300 268400 169100 156200 331000 486900 213300
2003-07 148900 327900 368600 128200 161100 271600 170900 156300 332800 489400 216900
2003-08 149900 330800 374600 128300 162800 274900 172900 156600 334300 493500 220600
2003-09 151000 333400 381100 128600 164600 278300 175000 157000 335800 498900 225200
2003-10 152200 336000 388300 128800 166500 282000 177300 157400 337600 505100 230900
2003-11 153400 338700 396200 128900 168400 286000 179500 157900 340000 512000 237400
2003-12 154600 343000 404500 129200 170000 290100 181900 158400 342400 519900 243700
2004-01 155800 348300 412600 129900 171600 294500 184700 158700 344600 527800 249500
2004-02 157000 352600 421200 131000 173300 299300 187800 159100 347200 535400 255500
2004-03 158500 355300 430900 132100 175000 304700 191000 159500 350300 543300 262300
2004-04 160000 358700 441700 133100 176800 310700 194700 159800 353400 552400 269600
2004-05 161200 362400 453600 134100 179000 316800 198900 160000 356400 561300 277400
2004-06 162400 365900 466300 135200 181200 323000 203200 160400 359100 569500 285700
2004-07 163700 369700 477700 136300 183700 329800 207500 160800 361400 578000 294000
2004-08 164900 374300 487200 137100 186200 337100 212400 161200 363900 586300 302200
2004-09 166100 379000 495000 137700 188800 344400 217200 161700 366300 594900 309500
2004-10 167300 383600 501400 138100 191100 351300 222100 162200 368500 604200 315900
2004-11 168600 388400 506800 138300 193400 358000 227200 162600 370700 614400 321500
2004-12 170300 392700 511800 138600 195900 364700 232500 163100 372900 625200 326400
2005-01 172400 397000 516700 139000 198500 371100 237800 163700 375100 636400 331200
2005-02 174200 401800 522200 139400 200900 377100 243700 164400 377300 647200 336000
2005-03 175700 407200 529000 139800 203100 383300 249900 164900 379300 657700 340900
2005-04 177100 412200 536700 140200 205400 390200 256600 165400 381200 667100 345700
2005-05 178400 416600 544300 140700 207700 397100 263300 166000 382800 675100 350700
2005-06 180200 420700 552100 140900 210300 403900 270200 166500 383700 682500 356000
2005-07 182200 424700 560800 140800 213000 410300 277300 166900 384100 689400 361600
2005-08 184100 428400 569800 140800 215400 415800 283800 167600 384400 695200 366900
2005-09 185700 432000 578300 140900 217600 420100 289400 168400 384700 699800 372200
2005-10 187200 435600 586100 141200 219700 423600 294500 169100 384600 703000 377800
2005-11 188800 438700 593300 141600 221700 426800 299100 169800 383800 705300 383300
2005-12 190000 441300 599400 142000 223700 429200 302400 170400 382800 707400 388000
2006-01 190900 443500 604200 142400 225100 430800 304600 170900 381800 708400 392100
2006-02 191500 445500 607400 142900 226200 431300 306900 171500 380500 707500 395500
2006-03 192400 447200 609800 143200 227200 431300 309300 171900 379100 705300 398500
2006-04 193200 448800 611200 143400 228400 431100 311100 172400 377900 703400 400800
2006-05 193900 449900 612600 143700 229300 430600 312100 172800 375900 701700 402300
2006-06 194300 450700 613900 144100 230100 429300 312400 173400 373300 699700 402700
2006-07 194400 451100 614100 144400 230700 427400 312000 174000 371100 697400 402500
2006-08 194500 451200 613000 144700 231000 425200 311200 174500 369000 695300 402100
2006-09 195100 451000 611700 144900 231100 423100 310000 174600 366500 693200 401400
2006-10 195500 450400 610600 145100 231200 420900 308900 174700 364100 691400 399400
2006-11 195700 449600 608300 145500 231000 418800 307700 174900 362500 689400 396300
2006-12 195800 448400 605200 145800 230800 416900 305900 174700 361300 687200 393000
2007-01 195900 447300 603500 146100 231100 415300 304400 173900 360400 685800 390200
2007-02 196300 446600 602600 146300 231500 414200 302900 173100 359700 684900 387500
2007-03 196700 446100 600000 146500 231600 413000 300600 172900 358900 684400 384800
2007-04 196500 445400 596700 146700 231400 411400 297600 173000 357800 684000 382100
2007-05 195800 444600 593200 146900 231300 409600 294000 173100 356700 683400 378900
2007-06 195200 443100 588500 147100 231100 407200 290200 173000 355400 682200 374900
2007-07 194800 441000 583200 147400 230900 404500 286500 172900 354000 681100 370400
2007-08 194500 439000 577900 147700 230600 401500 282600 173100 352700 679200 365600
2007-09 193600 437500 571700 148000 230200 398300 278200 173000 351400 675900 360400
2007-10 192400 436200 565900 148400 229600 394700 273600 172600 349900 670400 354700
2007-11 191500 434900 559700 148700 228700 390800 269400 172000 348500 664000 348300
2007-12 190200 433200 552300 148600 228300 386600 264700 171100 347300 657000 341400
2008-01 188400 431500 544200 147700 227900 381700 259300 170200 346100 648400 335000
2008-02 186800 429200 535300 146300 226900 375600 253200 169400 343800 637500 328100
2008-03 185700 425800 524400 144900 225400 369100 246700 168400 339800 626300 319600
2008-04 184400 421800 512300 143800 224200 363200 239900 166900 335800 616700 310400
2008-05 183300 417800 501100 142700 222900 357800 233600 165200 333300 607900 301400
2008-06 182200 413900 491500 141600 222100 352900 227600 163800 331900 598900 292200
2008-07 181200 410800 482500 140900 221600 348700 222000 162700 331000 590300 283800
2008-08 180000 408400 473700 140500 221000 345000 216000 161000 330300 581000 275600
2008-09 178500 405800 465900 140100 220100 341500 209500 158800 329100 571300 267300
2008-10 176500 402600 459500 139500 219200 337800 203000 156600 327600 562700 259200
2008-11 174100 398800 453800 138700 218200 333500 196700 154000 325700 555000 251600
2008-12 173500 395800 449700 137700 217800 330000 191500 151700 324100 549800 244900
2009-01 174100 394000 446400 136700 218000 327700 187800 150800 323000 546000 239200
2009-02 174000 392200 442000 135800 217900 325300 184100 150400 321300 539800 233200
2009-03 172700 389000 437400 135000 216900 322400 179500 149200 318500 531500 227400
2009-04 171700 385600 434100 134300 215400 319900 174900 147500 316500 524900 222500
2009-05 171100 382100 431400 133700 213800 317700 171100 146200 316100 520700 218100
2009-06 170900 379300 430000 133100 212900 316100 168300 145500 316700 519100 214400
2009-07 170300 377500 430000 132900 212400 315300 166000 145100 317900 519300 211600
2009-08 169600 376700 430600 132800 212400 314800 164100 144800 319600 520500 208800
2009-09 169200 376700 431300 132800 212600 314600 162800 144400 320900 521400 206600
2009-10 169300 376900 432200 132800 212800 314800 161900 144000 321700 522300 205400
2009-11 169200 377000 433400 132700 213400 315400 161000 143500 323000 525600 205000
2009-12 168300 377000 434800 132300 212300 315700 162000 144900 322700 525500 205400
2010-01 167500 376800 434800 132300 211000 316000 162600 146200 321300 525700 206300
2010-02 167100 376500 435900 132800 211200 316900 161300 145300 321800 530000 207100
2010-03 166600 376500 438200 132900 212800 318000 159500 143200 325100 532100 206600
2010-04 166200 376900 439300 132500 212900 317800 158900 143100 326400 529100 205700
2010-05 165600 377100 438000 132100 212400 316300 158100 142600 325400 527900 204700
2010-06 164300 376700 436300 132000 210100 314600 156400 141100 324100 526100 203400
2010-07 162700 375600 433500 131700 207800 313300 154400 139100 322700 521400 201900
2010-08 161700 373800 431200 131100 206400 311900 152800 137200 321000 518300 201700
2010-09 161300 371900 428300 130500 206200 310600 151600 135700 319500 516600 201100
2010-10 160900 370600 425200 130100 205400 309700 150600 134800 318500 514800 199700
2010-11 160200 370000 422400 129700 204300 309400 150300 134200 317600 510500 198700
2010-12 159200 368400 420300 129400 203000 309300 148500 132700 317800 507500 197700
2011-01 158200 365800 418200 129100 201500 308800 146100 131400 317000 503500 196100
2011-02 157400 364300 417200 129000 200000 308800 144800 130600 315200 499400 195300
2011-03 156700 363600 416200 128900 198600 308800 145400 130000 314700 497600 195000
2011-04 156300 362400 414600 128900 198100 308000 145700 128800 315600 497600 194100
2011-05 155800 361800 412500 128700 197900 307600 145300 127800 316400 494400 193500
2011-06 155100 362200 410100 128300 197700 307600 145000 127000 316600 491000 193400
2011-07 154700 361000 407600 127800 197100 306900 144900 125800 315500 488900 192600
2011-08 154200 358600 405100 127500 196300 306600 144700 124300 313600 487400 191300
2011-09 153400 356700 402900 127000 194700 306200 144800 123400 312800 484700 190000
2011-10 152800 354700 401200 126600 193100 305900 144700 122900 312300 482800 189200
2011-11 153000 352400 399700 126700 191700 306300 144400 122700 311600 482400 189100
2011-12 152700 350300 397600 126800 190800 306400 144300 122100 310700 481000 188900
2012-01 152000 348200 396200 126800 190000 306200 144700 120200 310900 477900 187700
2012-02 151700 346500 395600 127000 189300 307100 146000 119100 311500 477900 187300
2012-03 152100 346900 396600 127300 189300 308800 147700 119900 312700 481800 188400
2012-04 152400 347200 399200 127600 189200 310300 148900 120500 314400 486200 190100
2012-05 152800 347400 402200 128000 189000 311300 150200 120400 315800 491500 191000
2012-06 153300 347900 403900 128400 189400 311800 151800 120700 316600 497300 192400
2012-07 153800 348800 405800 128700 189700 312100 152300 120300 317500 503300 194200
2012-08 154200 347700 408700 128900 188600 311900 153400 120100 317800 507700 195300
2012-09 154900 346200 412600 129100 187600 311900 154900 120600 318400 514200 196800
2012-10 155800 345400 416900 129500 187600 313200 156500 120700 320200 522300 199300
2012-11 156700 346400 421100 130200 187900 314200 157600 120200 322300 529800 201800
2012-12 157200 346600 426500 130900 188000 314600 158900 120400 323400 535300 204500
2013-01 157700 346200 433800 131700 187500 316400 160400 121500 324700 544100 208100
2013-02 158500 347100 441000 132500 187700 319700 162300 122600 326900 557600 211900
2013-03 159500 349300 447100 133600 188600 323100 164100 123300 329600 573200 215800
2013-04 160400 351300 454700 134700 189700 327200 166100 124200 332700 589400 220400
2013-05 161300 354400 464600 135800 190900 331100 168400 125700 336300 602900 226100
2013-06 162700 357500 473600 136900 192400 334400 170900 127000 339100 612700 232500
2013-07 164100 360400 479200 138100 192900 337100 173800 128900 341400 617300 237900
2013-08 164800 362500 482800 139100 192700 339100 175700 130900 343300 621900 242500
2013-09 165500 363700 486900 139900 192500 341100 178000 132400 344900 628300 246700
2013-10 166300 364700 490900 140500 192600 342600 180500 134300 346400 635000 250400
2013-11 167400 366200 496000 140600 193000 344100 183100 136800 347400 638900 253900
2013-12 168600 367900 500600 141200 193500 346100 185300 138000 348300 644700 256600
2014-01 169300 369300 504500 142000 194100 347600 186900 138400 350000 653500 258700
2014-02 169800 369700 508600 142600 194400 348600 188600 139400 353500 662100 260600
2014-03 170500 368400 515600 143000 194300 349400 190700 141400 356600 671200 264300
2014-04 171900 371300 521100 143900 196600 351800 193900 143600 359800 677000 268600
2014-05 173400 374600 524000 145200 199400 355800 197300 145300 361700 679700 272500
2014-06 174500 375300 526300 146300 199900 358800 200000 146800 362500 683200 275100
2014-07 174800 374700 529200 147100 199200 359900 201300 148100 362300 688600 277100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment