Skip to content

Instantly share code, notes, and snippets.

@xinyu-usf
Last active March 3, 2016 20:28
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 xinyu-usf/9fc02534b079db2cbe91 to your computer and use it in GitHub Desktop.
Save xinyu-usf/9fc02534b079db2cbe91 to your computer and use it in GitHub Desktop.
ass3-line graph
median_house_value median_income housing_median_age total_rooms total_bedrooms population households latitude longitude
452600.00 8.33 41.00 880.00 129.00 322.00 126.00 37.88 -122.23
358500.00 8.30 21.00 7099.00 1106.00 2401.00 1138.00 37.86 -122.22
352100.00 7.26 52.00 1467.00 190.00 496.00 177.00 37.85 -122.24
341300.00 5.64 52.00 1274.00 235.00 558.00 219.00 37.85 -122.25
342200.00 3.85 52.00 1627.00 280.00 565.00 259.00 37.85 -122.25
269700.00 4.04 52.00 919.00 213.00 413.00 193.00 37.85 -122.25
299200.00 3.66 52.00 2535.00 489.00 1094.00 514.00 37.84 -122.25
241400.00 3.12 52.00 3104.00 687.00 1157.00 647.00 37.84 -122.25
226700.00 2.08 42.00 2555.00 665.00 1206.00 595.00 37.84 -122.26
261100.00 3.69 52.00 3549.00 707.00 1551.00 714.00 37.84 -122.25
281500.00 3.20 52.00 2202.00 434.00 910.00 402.00 37.85 -122.26
241800.00 3.27 52.00 3503.00 752.00 1504.00 734.00 37.85 -122.26
213500.00 3.08 52.00 2491.00 474.00 1098.00 468.00 37.85 -122.26
191300.00 2.67 52.00 696.00 191.00 345.00 174.00 37.84 -122.26
159200.00 1.92 52.00 2643.00 626.00 1212.00 620.00 37.85 -122.26
140000.00 2.13 50.00 1120.00 283.00 697.00 264.00 37.85 -122.26
152500.00 2.77 52.00 1966.00 347.00 793.00 331.00 37.85 -122.27
155500.00 2.12 52.00 1228.00 293.00 648.00 303.00 37.85 -122.27
158700.00 1.99 50.00 2239.00 455.00 990.00 419.00 37.84 -122.26
162900.00 2.60 52.00 1503.00 298.00 690.00 275.00 37.84 -122.27
147500.00 1.36 40.00 751.00 184.00 409.00 166.00 37.85 -122.27
159800.00 1.71 42.00 1639.00 367.00 929.00 366.00 37.85 -122.27
113900.00 1.73 52.00 2436.00 541.00 1015.00 478.00 37.84 -122.27
99700.00 2.18 52.00 1688.00 337.00 853.00 325.00 37.84 -122.27
132600.00 2.60 52.00 2224.00 437.00 1006.00 422.00 37.84 -122.27
107500.00 2.40 41.00 535.00 123.00 317.00 119.00 37.85 -122.28
93800.00 2.46 49.00 1130.00 244.00 607.00 239.00 37.85 -122.28
105500.00 1.81 52.00 1898.00 421.00 1102.00 397.00 37.85 -122.28
108900.00 1.64 50.00 2082.00 492.00 1131.00 473.00 37.84 -122.28
132000.00 1.69 52.00 729.00 160.00 395.00 155.00 37.84 -122.28
122300.00 1.93 49.00 1916.00 447.00 863.00 378.00 37.84 -122.28
115200.00 1.96 52.00 2153.00 481.00 1168.00 441.00 37.84 -122.28
110400.00 1.80 48.00 1922.00 409.00 1026.00 335.00 37.84 -122.27
104900.00 1.38 49.00 1655.00 366.00 754.00 329.00 37.83 -122.27
109700.00 2.73 51.00 2665.00 574.00 1258.00 536.00 37.83 -122.27
97200.00 1.49 49.00 1215.00 282.00 570.00 264.00 37.83 -122.27
104500.00 1.10 48.00 1798.00 432.00 987.00 374.00 37.83 -122.27
103900.00 1.41 52.00 1511.00 390.00 901.00 403.00 37.83 -122.28
191400.00 3.48 52.00 1470.00 330.00 689.00 309.00 37.83 -122.26
176000.00 2.59 52.00 2432.00 715.00 1377.00 696.00 37.83 -122.26
155400.00 2.10 52.00 1665.00 419.00 946.00 395.00 37.83 -122.26
150000.00 1.29 51.00 936.00 311.00 517.00 249.00 37.83 -122.26
118800.00 1.02 49.00 713.00 202.00 462.00 189.00 37.84 -122.26
188800.00 3.96 52.00 950.00 202.00 467.00 198.00 37.84 -122.26
184400.00 3.01 52.00 1443.00 311.00 660.00 292.00 37.83 -122.26
182300.00 2.68 52.00 1656.00 420.00 718.00 382.00 37.83 -122.26
142500.00 2.03 50.00 1125.00 322.00 616.00 304.00 37.83 -122.26
137500.00 1.73 43.00 1007.00 312.00 558.00 253.00 37.82 -122.27
187500.00 0.95 40.00 624.00 195.00 423.00 160.00 37.82 -122.26
112500.00 1.77 40.00 946.00 375.00 700.00 352.00 37.82 -122.27
171900.00 0.92 21.00 896.00 453.00 735.00 438.00 37.82 -122.27
93800.00 1.50 43.00 1868.00 456.00 1061.00 407.00 37.82 -122.27
97500.00 1.11 41.00 3221.00 853.00 1959.00 720.00 37.82 -122.27
104200.00 1.25 52.00 1630.00 456.00 1162.00 400.00 37.82 -122.27
87500.00 1.61 52.00 1170.00 235.00 701.00 233.00 37.82 -122.28
83100.00 1.41 52.00 945.00 243.00 576.00 220.00 37.82 -122.28
87500.00 1.51 52.00 1238.00 288.00 622.00 259.00 37.82 -122.28
85300.00 0.82 52.00 1489.00 335.00 728.00 244.00 37.82 -122.28
80300.00 1.22 52.00 1387.00 341.00 1074.00 304.00 37.82 -122.28
60000.00 2.56 2.00 158.00 43.00 94.00 57.00 37.82 -122.29
75700.00 3.39 52.00 1121.00 211.00 554.00 187.00 37.83 -122.29
75000.00 6.12 49.00 135.00 29.00 86.00 23.00 37.82 -122.29
86100.00 0.90 50.00 760.00 190.00 377.00 122.00 37.81 -122.29
76100.00 1.19 52.00 1224.00 237.00 521.00 159.00 37.81 -122.30
73500.00 2.59 48.00 828.00 182.00 392.00 133.00 37.81 -122.30
78400.00 1.17 52.00 1010.00 209.00 604.00 187.00 37.81 -122.30
84400.00 0.81 48.00 1455.00 354.00 788.00 332.00 37.81 -122.30
81300.00 2.61 52.00 1027.00 244.00 492.00 147.00 37.80 -122.29
85000.00 1.85 52.00 572.00 109.00 274.00 82.00 37.81 -122.30
129200.00 0.98 46.00 2801.00 644.00 1823.00 611.00 37.81 -122.29
82500.00 1.77 26.00 768.00 152.00 392.00 127.00 37.81 -122.29
95200.00 0.73 46.00 935.00 297.00 582.00 277.00 37.81 -122.29
75000.00 1.75 49.00 844.00 204.00 560.00 152.00 37.81 -122.29
67500.00 0.50 46.00 12.00 4.00 18.00 7.00 37.81 -122.29
137500.00 2.48 20.00 835.00 161.00 290.00 133.00 37.81 -122.29
177500.00 0.92 17.00 1237.00 462.00 762.00 439.00 37.81 -122.28
102100.00 2.45 36.00 2914.00 562.00 1236.00 509.00 37.81 -122.28
108300.00 1.11 19.00 1207.00 243.00 721.00 207.00 37.81 -122.28
112500.00 0.80 23.00 1745.00 374.00 1054.00 325.00 37.81 -122.29
131300.00 2.01 38.00 684.00 176.00 344.00 155.00 37.80 -122.28
162500.00 1.50 17.00 924.00 289.00 609.00 289.00 37.81 -122.28
112500.00 1.17 52.00 210.00 56.00 183.00 56.00 37.81 -122.27
112500.00 1.52 52.00 340.00 97.00 200.00 87.00 37.81 -122.28
137500.00 0.81 52.00 386.00 164.00 346.00 155.00 37.81 -122.28
118800.00 1.81 35.00 948.00 184.00 467.00 169.00 37.81 -122.28
98200.00 2.41 52.00 773.00 143.00 377.00 115.00 37.81 -122.28
118800.00 0.98 40.00 880.00 451.00 582.00 380.00 37.81 -122.27
162500.00 0.76 10.00 875.00 348.00 546.00 330.00 37.81 -122.27
137500.00 0.97 10.00 105.00 42.00 125.00 39.00 37.80 -122.27
500001.00 1.24 52.00 249.00 78.00 396.00 85.00 37.80 -122.27
162500.00 2.09 16.00 994.00 392.00 800.00 362.00 37.80 -122.27
137500.00 0.87 52.00 215.00 87.00 904.00 88.00 37.80 -122.28
162500.00 0.75 52.00 96.00 31.00 191.00 34.00 37.80 -122.28
187500.00 2.64 27.00 1055.00 347.00 718.00 302.00 37.79 -122.27
179200.00 1.85 39.00 1715.00 623.00 1327.00 467.00 37.80 -122.27
130000.00 2.01 36.00 5329.00 2477.00 3469.00 2323.00 37.80 -122.26
183800.00 2.83 31.00 4596.00 1331.00 2048.00 1180.00 37.82 -122.26
125000.00 2.01 29.00 335.00 107.00 202.00 91.00 37.81 -122.26
170000.00 1.22 22.00 3682.00 1270.00 2024.00 1250.00 37.82 -122.26
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style> /* set the CSS */
body { font: 12px Arial;
width:960px;
margin: 0, auto;}
path {
stroke: steelblue;
stroke-width: 2;
fill: none;
}
.axis path,
.axis line {
fill: none;
stroke: grey;
stroke-width: 1;
shape-rendering: crispEdges;
}
</style>
</head>
<body>
<!-- load the d3.js library -->
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
// Set the dimensions of the canvas / graph
var margin = {top: 30, right: 20, bottom: 30, left: 50},
width = 950 - margin.left - margin.right,
height = 300 - margin.top - margin.bottom;
// Parse the date / time
//var parseDate = d3.time.format("%d-%b-%y").parse;
// Set the ranges
//var x = d3.time.scale().range([0, width]);
var x = d3.scale.linear().range([0,width]);
var y = d3.scale.linear().range([height, 0]);
// Define the axes
var xAxis = d3.svg.axis().scale(x)
.orient("bottom").ticks(10);
var yAxis = d3.svg.axis().scale(y)
.orient("left").ticks(5);
// Define the line
var valueline = d3.svg.line()
//.x(function(d) { return x(d.median_house_value); })
.x(function(d,i) { return x(i); })
.y(function(d) { return y(d.total_rooms); });
// Adds the svg canvas
var svg = d3.select("body")
.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 + ")");
// Get the data
d3.csv("house_100.csv", function(error, data) {
data.forEach(function(d) {
d.median_house_value = parseFloat(d.median_house_value);
d.total_rooms = parseFloat(d.total_rooms);
});
// Scale the range of the data
//x.domain([0, d3.max(data, function(d) { return d.median_house_value; })]);
x.domain([0, data.length]);
y.domain([0, d3.max(data, function(d) { return d.total_rooms; })]);
// Add the valueline path.
svg.append("path")
.attr("class", "line")
.attr("d", valueline(data));
// Add the X Axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
// Add the Y Axis
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment