Published
Edited
Mar 9, 2020
Insert cell
md`# Assignment 2: Choropleth Mapping`
Insert cell
d3 = require("d3@5")
Insert cell
import {legend} from "@d3/color-legend"
Insert cell
simple = require("simple-statistics@7.0.7/dist/simple-statistics.min.js")
Insert cell
format = d => `${d}%`
Insert cell
topojson = require("topojson-client@3")
Insert cell
jamaica = FileAttachment("NewJamaica@5.json").json()
Insert cell
jamaica_features = topojson.feature(jamaica, jamaica.objects.NewJamaica)
Insert cell
csv_data = d3.csvParse(await FileAttachment("PopParish (1).csv").text(),({Name,FID,CV_adjusted, y2011,y2018}) => [+FID, [+CV_adjusted, Name]])
Insert cell
CV_adjusted = Array.from(csv_data.values(), d => d[1][0])
Insert cell
data = Object.assign(new Map(csv_data), {title: ["Adjusted Coefficient Variation"]})
Insert cell
color = ["#edf8b1", "#2c7fb8"]
Insert cell
linear = d3.scaleLinear()
.domain([0.3, d3.max(CV_adjusted)])
.range(color)
Insert cell
width = 975
Insert cell
height = 610
Insert cell
projection = d3.geoTransverseMercator().rotate([94,0]).fitExtent([[80, 80], [width, height]],jamaica_features);
Insert cell
//Using a path generator to project geometry onto the map
path = d3.geoPath().projection(projection);
Insert cell
md`# Jamaica Population: Adjusted Coefficient Variation for 2011-2018
For Pattern Interpretations, see below.`
Insert cell
// Interpretation of the patterns:

//by Angelina Evans

//The change in population of all the parishes in Jamaica were so small that it would be difficult to map out, not to mention not very useful. Instead, coefficient variation is used for this map.This is the extent of variability in relation to the population's mean.

//The CV variation of each parish was still extremely small. Each value didn't vary much between others. The numbers were so small that the CV needed to be adjusted, taking out the beginning identical numbers so the user could see the differences more easily.

// Even though the numbers are very small, I can try to point out the differences and get an idea of why there are differences, though very small.

//The parish with the highest adjusted CV is Saint Catherine. The adjusted coefficient variation was 0.647730608. This was the only parish to have a value greater than .6

//The variation being the largest in Saint Catherine may have something to do with its fast population growth: This is one of the fastest growing parishes in Jamaica. One of the reasons for this is because of its economy. It has the largest economy of all the parishes. Manufacturing and agriculture are big industries there.

//https:jis.gov.jm/information/parish-profiles/parish-profile-st-catherine/.

// The Jamaican parish with the smallest adjusted coefficient variation is Manchester, with a value of 0.306472566

//I decided to learn a little about Manchester as well, but I could not connect the information to the low variation.

chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.attr("transform", "translate(360,380)")
.append(() =>
legend({
color: linear,
title: data.title,
tickFormat: ".2f"
})
);

svg.append("g")
.selectAll("path")
.data(jamaica_features.features)
.join("path")
.attr("stroke", "black")
.attr("stroke-linejoin", "round")
.attr("fill", function(d){
var value = data.get(+d.properties.id)[0]
if(value == 0)
return "white"
else
return linear(data.get(+d.properties.id)[0])
})
// .attr("fill", d => linear(data.get(+d.properties.id)[0]))
.attr("d", path)
.append("title")
.text(function(d){
var value = data.get(+d.properties.id)[0]
if(value == 0)
return " Coefficient variation for " + data.get(+d.properties.id)[1]+" is unknown!"
})
//.text(d => " Coefficient variation for " + data.get(+d.properties.id)[1]+" is "+data.get(+d.properties.id)[0]);

return svg.node();
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more