This line defines the variable nebraska to a FileAttachment object that opens the nebraska_counties_wgs82 json. This file contains the polygon information to draw the counties of nebraska.
This line parses the NebraskaPop.csv, creating a new table of the format: FIPS -> [percent under the age of 5] and creates the percentage variable with each county.
This converts the csv data from a 2d array to a Map following the structure of "FIPS" -> percent of population under 5. It creates the numerical value appropriate for a choropleth map.
This creates an array containing a gradient from pink to purple which I made using color brewer. It also is named PkPu so the colors do not have to be put into the map individually.
This line defines the values that the data should be broken up at using the natural breaks classification calculated by kmeans clustering. Kmeans clustering finds natural groupings in the data by minimizing variation. The data for percentage under 5 and the color scheme is input here. The amount of colors used determines the number of classes so by putting in 5 colors, I get 5 classes. The v.pop finds the largest values for each class to use as an upper boundary.
This creates a new threshold scale using the natural breaks for its domain and inputs the color scheme I made earlier. I chose natural breaks because the data is skewed to the right and their is an outlier so natural breaks would work best to clearly represent the data. I chose 5 colors because I wanted to show variation in the data but the data range is not big enough to have more than 5 bins and I don't want to colors to be hard to distinguish.
The projection line of code creates and sizes the map projection into Albers USA projections. The fitExtent scales and positions the map so all data can fit between the margin, width, and height that I set.
This creates the choropleth map SVG, the legend, and draws and colors each county.
The legend is added by svg.append as it creates a group element and moves it to be positioned next to the map. The legend is generated by append (() => legend which is a legend function and inserts it into the SVG. tickFormat makes the number only 1 decimal place.
svg.append("g") contains all county shapes and creates a path element. ("stroke", "black"), ("stroke-linejoin", "round"), and ("stroke-width", 1) defines the black outline around the boarders, rounds the corners where they meet, and give it a thickness of 1 pixel line.
.attr("fill".... gives each of the counties their color by converting the value to a color. .attr("d", path) converts geo coordinates into svg drawing instructions to draw the shape onto the map.
The hover tool is created by .append("title") and .text(d... lines which names Percentage Under 5 and add the data number by the county FIPS.
Set the width of the map to 990. The reason I set the height to 610 and the width to 990 because Nebraska is longer than is it tall, so setting a greater width ensures that Nebraska fits nicely inside the box.
Set the height of the map to 610. The reason I set the height to 610 and the width to 990 because Nebraska is longer than is it tall, so setting a greater width ensures that Nebraska fits nicely inside the box.
Allow 65 units of white space around the actual Nebraska drawing. This is a good amount because there is not an awkward amount of space around Nebraska, and the state is not touching the borders.