Skip to content

Instantly share code, notes, and snippets.

@ericd9799
Created February 7, 2018 21:01
Show Gist options
  • Save ericd9799/35168d156b50d1183a245693502cdfbe to your computer and use it in GitHub Desktop.
Save ericd9799/35168d156b50d1183a245693502cdfbe to your computer and use it in GitHub Desktop.
CS725 - HW4 - Line Chart
license: mit

**CS 725 - Spring 2018 - Homework 4 - Line Chart **

List the marks/channels used and the data/attributes they map to.

  • The point mark represents the commitment amount for the particular year.
  • The line mark represents the temporal connection between each point.
  • The horizontal spatial position represents the year which is a categorical attribute.
  • The vertical spatial position represents the commitment amount which is a quantitative attribute.

Write an explanation of what the chart shows.

  • The line chart displays the aggregated commitment amount for each year the United States provided monetary aid to countries. The line chart will be used to answer the question, can we see the increase or decrease of a country's donation over time? To answer this question, I will need to look for a trend over the years.

Point out 1 - 2 interesting insights (i.e., things you learned from the chart)

  • After 2009, there was a significant increase in the times the United States provided monetary aid than prior years because there is a sky-rocketing increase in aggregated aid amount.
  • In 2003, the United States' aggregated aid commitment is the lowest compared to the other years.

References

forked from ericd9799's block: CS725 - HW4 - Line Chart

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<div><svg id="lineChart" width="960" height="500"></svg></div>
<script>
var chart = d3.select("#lineChart"),
margin = {top:20, right:20, bottom:30, left:70},
width = +chart.attr("width") - margin.left - margin.right,
height = +chart.attr("height") - margin.top - margin.bottom,
g = chart.append("g").attr("transform", "translate("+margin.left+","+margin.top+")");
//Parse and return new format for year
var parseTime = d3.timeParse("%Y");
//Create time range
var x = d3.scaleTime().range([0, width]);
//Create integer range
var y = d3.scaleLinear().rangeRound([height, 0]);
//Generate line using the data
var line = d3.line()
.x(function(d) {return x(d.year);})
.y(function(d) {return y(d.commitment_amount_usd_constant);});
d3.csv("LineChart_AidData_Aggregate.csv", function(d){
d.year = parseTime(d.year); //Convert year into new format
d.commitment_amount_usd_constant = +d.commitment_amount_usd_constant; //Convert string to numeric
return d;
}, function(error, data){
//Translate domain to range
//d3.extent() returns the min and max value in array using natural order
x.domain(d3.extent(data, function(d){return d.year;}));
y.domain(d3.extent(data, function(d){return d.commitment_amount_usd_constant;}));
g.append("g")
.attr("transform", "translate(0,"+height+")")
.call(d3.axisBottom(x)); //Creation of x-axis
g.append("g")
.call(d3.axisLeft(y)) //Creation of y-axis
.append("text")
.attr("fill", "black")
.attr("transform", "rotate(-90)")
.attr("y",4)
.attr("dy", "0.75em")
.style("text-anchor", "end")
.text("Aggregate Commitment Amount USD ($)");
g.append("text")
.attr("fill", "black")
.attr("x", width/2)
.attr("y", height+margin.bottom)
.style("text-anchor", "middle")
.text("Year");
g.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("strok-width", 1.5)
.attr("d", line);
});
</script>
</body>
year donor recipient commitment_amount_usd_constant coalesced_purpose_code coalesced_purpose_name
2002 United States Indonesia 840103.00 72010 Material relief assistance and services
2002 United States South of Sahara, regional 3024850.00 41030 Bio-diversity
2003 United States Poland 99014.00 33110 Trade policy and administrative management
2005 United States Brazil 325556.00 41020 Biosphere protection
2005 United States Kazakhstan 25211.00 52010 Food security programmes/food aid
2005 United States Kazakhstan 791419.00 12220 Basic health care
2005 United States Zambia 3588790.00 13040 Std control including hiv/aids
2006 United States Cambodia 43524.00 13040 Std control including hiv/aids
2006 United States Cambodia 955413.00 15250 Land mine clearance
2006 United States Congo, Dem. Rep. 3047770.00 60020 Debt forgiveness
2006 United States Djibouti 53079.00 43010 Multisector aid
2006 United States Honduras 173036.00 52010 Food security programmes/food aid
2006 United States Indonesia 297240.00 52010 Food security programmes/food aid
2006 United States Nicaragua 893842.00 52010 Food security programmes/food aid
2006 United States Samoa 1088110.00 43010 Multisector aid
2006 United States Somalia 450106.00 72040 Emergency food aid
2006 United States Uganda 173036.00 12250 Infectious disease control
2007 United States Afghanistan 113434.00 15150 Strengthening civil society
2007 United States Bilateral, unspecified 30906.00 73010 Reconstruction relief and rehabilitation
2007 United States Bilateral, unspecified 14224300.00 13020 Reproductive health care
2007 United States Mexico 31180.00 41030 Bio-diversity
2007 United States Serbia 2632780.00 43010 Multisector aid
2007 United States South Africa 18316.00 24040 Informal/semi-formal fin. intermed.
2007 United States South of Sahara, regional 72850.00 15150 Strengthening civil society
2008 United States Dominican Republic 3164190.00 43010 Multisector aid
2008 United States Nicaragua 11676.00 13030 Family planning
2008 United States Serbia 361726.00 33110 Trade policy and admin. management
2008 United States South of Sahara, regional 1088390.00 13020 Reproductive health care
2009 United States Jamaica 2790000.00 43010 Multisector aid
2009 United States Mozambique 59640.00 41030 Bio-diversity
2009 United States Myanmar 11739.00 11420 Higher education
2009 United States Nigeria 3500000.00 12263 Tuberculosis control
2009 United States Pakistan 176180.00 43010 Multisector aid
2009 United States South Africa 459957.00 13040 Std control including hiv/aids
2009 United States Sudan 1484000.00 31120 Agricultural development
2009 United States Thailand 60000.00 15210 Security system management and reform
2009 United States Ukraine 54950.00 15130 Legal and judicial development
2009 United States Ukraine 540000.00 33110 Trade policy and admin. management
2009 United States Uzbekistan 50000.00 15150 Strengthening civil society
2009 United States Zimbabwe 750000.00 72010 Material relief assistance and services
2010 United States Asia, regional 21235.00 91010 Administrative costs
2010 United States Bangladesh 16030.00 23005 Energy generation and supply, purpose unspecified or does not fit under any other applicable codes
2010 United States Bilateral, unspecified 73172.00 43010 Multisector aid
2010 United States Bilateral, unspecified 1187970.00 31120 Agricultural development
2010 United States Bilateral, unspecified 101905000.00 15130 Legal and judicial development
2010 United States Colombia 317137.00 31120 Agricultural development
2010 United States Congo, Dem. Rep. 706146.00 52010 Food aid/Food security programmes
2010 United States Haiti 49499.00 99810 Sectors not specified
2010 United States Iraq 91222.00 43010 Multisector aid
2010 United States Kyrgyz Republic 43765.00 91010 Administrative costs
2010 United States Liberia 45890.00 15170 Women's equality organisations and institutions
2010 United States Moldova 98997.00 11430 Advanced tech. & managerial training
2010 United States Pakistan 6330960.00 16010 Social/welfare services
2010 United States Palestinian Adm. Areas 4949860.00 12100 Health, general, combinations of activities
2010 United States Paraguay 218784.00 24040 Informal/semi-formal fin. intermed.
2010 United States Philippines 3891910.00 52010 Food security programmes/food aid
2010 United States Serbia 269.00 91010 Administrative costs
2010 United States Zimbabwe 34497.00 91010 Administrative costs
year donor commitment_amount_usd_constant
2002 United States 3864953
2003 United States 99014
2005 United States 4730976
2006 United States 7175156
2007 United States 17123766
2008 United States 4625982
2009 United States 9936466
2010 United States 119982343
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment