Skip to content

Instantly share code, notes, and snippets.

@niphadkarneha
Last active February 13, 2019 12:56
Show Gist options
  • Save niphadkarneha/11bac91ab467a3d0a0f4f1f03eeb5bc5 to your computer and use it in GitHub Desktop.
Save niphadkarneha/11bac91ab467a3d0a0f4f1f03eeb5bc5 to your computer and use it in GitHub Desktop.
LineChartHW4
license: mit

Built with blockbuilder.org

Q1. List the marks/channels used and the data/attributes they map to. Answer: The visual mark and the attributes used to represent the data in this line chart is line, points, and shape. These two quantitative data points are located on the x and y axis of the 2D plane to represent the data which maps the Total number of Faculty members on the y-axis and the Total number of students on the x-axis. The idea being their is a positive correlation between these two datasets, as one variable increases so does the other. As the trend was not obvious in the scatterplot I was curious to see if it is apparent in a line chart, purely because of the simiplicity of the design.

Q2. Write an explanation of what the chart shows point out 1-2 interesting insights (i.e., things you learned from the chart) include links to any examples or helpful tutorials that you used.
Answer: As one can see their is an increasing/positive trend and a positive correlation between the two components. As the number of students increase so does the number of Faculty members.

References:

  1. https://beta.observablehq.com/@mbostock/d3-line-chart
    2.https://gist.github.com/gordlea/27370d1eea8464b04538e6d8ced39e89
  2. https://bl.ocks.org/pstuffa/26363646c478b2028d36e7274cedefa6
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script> <!-- for color scales -->
<style>
body {font-family: calibri;}
.axis {font: 14px calibri;}
.label {font: 16px calibri;}
.line {fill: none;stroke: #ff7265;stroke-width: 5;}
.dot {fill: #5900ff;stroke: #ff3d3d;}
/*End quoted code */
</style>
<body>
<h2>Line Chart</h2>
<div><svg id="chart2" width="644" height="400"></svg></div>
<script>
var svg2 = d3.select("#chart2"),
margin = {top: 20, right: 20, bottom: 30, left: 40},
width = +svg2.attr("width") - margin.left - margin.right,
height = +svg2.attr("height") - margin.top - margin.bottom;
var x2 = d3.scaleBand().rangeRound([0, width]).padding(0.8),
y2 = d3.scaleLinear().rangeRound([height, 0]);
var g2 = svg2.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Set line generator based upon code by Gord Lea at https://bl.ocks.org/gordlea/27370d1eea8464b04538e6d8ced39e89
var line = d3.line()
.x(function(d) { return x2(d.numStudents); })
// set the x values for the line generator
.y(function(d) { return y2(parseInt(d.Faculty)); })
.curve(d3.curveMonotoneX);
// load data
//ScatterPlot2 numStudents in increasing order
//ScatterPlot3 Faculty in increasing order
d3.csv("ScatterPlot3.csv").then(function(data) {
x2.domain(data.map(function(d) { return d.numStudents; }));
y2.domain([0, d3.max(data, function(d) { return +d.Faculty; })]);
// x-axis
g2.append("g")
.attr("class", "axis axis--x")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x2));
// x-axis label
g2.append("text")
.attr("class", "label")
.attr("x", 335-margin.right)
.attr("y", 410-margin.bottom)
.style("text-anchor", "begin")
.text ("Number of Students")
// y-axis
g2.append("g")
.attr("class", "axis axis--y")
.call(d3.axisLeft(y2).ticks(13, "#"));
// y-axis label
g2.append("text")
.attr("class", "label")
.attr("x", 0-margin.left)
.attr("y", 0-margin.top/2)
.style("text-anchor", "begin")
.text ("Number of Faculty")
g2.append("g").append("path")
.data([data])
.attr("class", "line")
.attr("d", line);
g2.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot") // Assign a class for styling
.attr("cx", function(d) { return x2(d.numStudents); })
.attr("cy", function(d) { return y2(d.Faculty); })
.attr("r", 4 )
;
});
</script>
</body>
</html>
country numStudents Faculty
Albania 800 50
Brazil 24170 1728
Bulgaria 1116 79
Canada 166134 8257
China 6900 830
England 436465 9593
France 46911 6145
India 1990 215
Iran 114428 553
Italy 53830 4210
Japan 51942 4116
Jordan 17849 4116
Lebanon 6342 653
Mexico 48249 5124
Netherlands 49939 6171
Philippines 10688 817
Puerto Rico 15949 1649
Romania 38140 838
Russia 339 30
South Korea 48013 5286
Sri Lanka 22649 971
UK 802219 4083
country numStudents Faculty
Russia 339 30
Albania 800 50
Bulgaria 1116 79
India 1990 215
Lebanon 6342 653
China 6900 830
Philippines 10688 817
Puerto Rico 15949 1649
Jordan 17849 4116
Sri Lanka 22649 971
Brazil 24170 1728
Romania 38140 838
France 46911 6145
South Korea 48013 5286
Mexico 48249 5124
Netherlands 49939 6171
Japan 51942 4116
Italy 53830 4210
Iran 114428 553
Canada 166134 8257
England 436465 9593
UK 802219 4083
country numStudents Faculty
Russia 339 30
Albania 800 50
Bulgaria 1116 79
India 1990 215
Iran 114428 553
Lebanon 6342 653
Philippines 10688 817
China 6900 830
Romania 38140 838
Sri Lanka 22649 971
Puerto Rico 15949 1649
Brazil 24170 1728
UK 802219 4083
Jordan 17849 4116
Japan 51942 4116
Italy 53830 4210
Mexico 48249 5124
South Korea 48013 5286
France 46911 6145
Netherlands 49939 6171
Canada 166134 8257
England 436465 9593
Country numStudents Faculty Endowment
Albania 800 50 3000000000
Bulgaria 1116 79 17400000000000
Denmark 33899 0 5270000000000000
Finland 34200 0 624000000000000
France 46911 6145 166000000
Italy 53830 4210 562000000000000
Netherlands 49939 6171 382700660000000
Romania 38140 838 120000000000000
United Kingdom 802219 4083 802995072000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment