This draws map, symbols, and legend. You can customize the drawing colors, thickness, and opacity. It also fills the polygons with associated radius. I chose the county outline to be black so it would pop compared to the gray county fill and the light pink circles. I upped the circle outline thickness to 1 from .5 so its easier to see the differences in circle sizes. I kept the symbol a circle because it fits best with the shape of the counties and easier to differentiate between smaller counties. The legend is created with "const legendGroup = svg.append("g")" and then is followed by parameters which let you pick the distance between each legend item. The hover text feature is added in the ".text(d =>" line of code which pulls the idName which is CntyName attribute and the final attribute which is the number percentage.
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. This creates a new threshold scale using the natural breaks for its domain and inputs the color scheme. 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 4 colors because I wanted to show variation in the data but the data range is not big enough to have more than 4 bins and I don't want to colors to be hard to distinguish.
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.
For each county, create a new attribute in its properties with finalAttributeName as the key. The value is defined by the total population under 5 years old divided by the total estimated population, times 100. The values are retrieved in the properties of the county, indexed by orgAttributeName and normalizationAttribute.
Define an array of all values of percentage of population under 5. The values are retrieved from points > features > [county number] > properties > finalAttributeName. Takes final attribute and turns it into a feature array and add plus sign to make sure it is numeric.
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.
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.
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.
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.