CS-GY 6313 - Information Visualization
New York University
2025-10-24
| User Interface | Graphics Library | Notebook(s) |
|---|---|---|
| observablehq.com | D3 | Week 8 Lab Notebook |
Today we will be a exploring the following topics:
| Milestone | Due Date | Details |
|---|---|---|
| Data Analysis & Sketches | Nov 3 | Data tables and visualization sketches |
| First Draft | Nov 17 | Initial D3 implementations |
| Second Draft | Dec 1 | Refined narrative and polished visualizations |
| Final Submission | Dec 8 | Complete project with presentation |
| URL To Guides | Example Github Repo | Example Dashboard |
|---|---|---|
| Framework Guides | Repository | Dashboard |
GeoJSON is an open standard format designed for representing simple geographical features, along with their non-spatial attributes. It is based on the JSON format. - Wikipedia
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}Point, Polygon, MultiPolygon, etc.Let’s download map data for the US states from https://gadm.org/data.html, then simplify using https://mapshaper.org/.
// Define parameters, svg, and chart (we've covered this by now a lot)
const width = 400, height = 250, margins=50;
// Create our SVG and Chart
// ...
// Need a projection, with `.scale()`, `.center()`, and `.translate()`
const projection = d3.geoMercator()
.scale(200)
.center([-98, 39]) // Lat/Lon of the U.S.
.translate([width/2, height*0.75]);
/*
// ALTERNATIVE: Let D3 attempt to fit the data
const projection = d3.geoMercator()
.fitSize([width, height], usa);
*/
// `d3.geoPath()` returns a function that can be called later.
const path = d3.geoPath().projection(projection);
// Render our chart.
chart.append("g")
.selectAll("path")
.data(usa.features)
.enter()
.append("path")
.attr("d", path) // Draw each state
.attr('fill','#ccc') // Stylize our states
.style("stroke", "#000");// Define parameters, svg, and chart (we've covered this by now a lot)
const width = 400, height = 250, margins=50;
// Create our SVG and Chart
// ...
// Need a projection, with `.scale()`, `.center()`, and `.translate()`
const projection = d3.geoMercator()
.scale(200)
.center([-98, 39]) // Lat/Lon of the U.S.
.translate([width/2, height*0.75]);
/*
// ALTERNATIVE: Let D3 attempt to fit the data
const projection = d3.geoMercator()
.fitSize([width, height], usa);
*/
// `d3.geoPath()` returns a function that can be called later.
const path = d3.geoPath().projection(projection);
// Render our chart.
chart.append("g")
.selectAll("path")
.data(usa.features)
.enter()
.append("path")
.attr("d", path) // Draw each state
.attr('fill','#ccc') // Stylize our states
.style("stroke", "#000");
Sometimes, your GeoJSON will have inverted coordinates. **D3 expects coordinates to be [longitude, latitude]:
Point coordinates are in x, y order (easting, northing for projected coordinates, longitude, and latitude for geographic coordinates) - specs
GeoJSON has an unspoken property called the “winding order”. Basically:
You may produce weird bugs if the winding order is reversed.
d3.geoAzimuthalEqualArea()d3.geoAzimuthalEquidistant()d3.geoOrthographic()d3.geoConicConformal()d3.geoConicEqualArea()d3.geoAlbers()
d3.geoMercator()d3.geoEquirectangular()d3.geoEqualEarth()Attempt to generate the geodata of 3 separate countries other than the USA. You can use any of the references mentioned before for getting your ShapeFiles, converting them into GeoJSON, and troubleshooting their issues upon importing them.
