This is a Population Map of Kentucky Counties created using D3.js, a Census 2010 Shapefile and GDAL (for geospatial data processing), inspired by the American Community Survey Handbook.
Last active
September 7, 2017 22:45
-
-
Save ccarpenterg/5143024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.background { | |
fill: none; | |
} | |
#states { | |
fill: none; | |
stroke: #fff; | |
} | |
#counties, .legend { | |
stroke: green; | |
} | |
.legend { | |
stroke-width: 0.3px; | |
} | |
.description { | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
font-size: 14px; | |
line-height: 20px; | |
color: #333; | |
} | |
#map { | |
border: 1px solid #DEDEDE; | |
} | |
.tier-1 { fill:rgb(229, 245, 224); } | |
.tier-2 { fill:rgb(161, 217, 155); } | |
.tier-3 { fill:rgb(49, 163, 84); } | |
</style> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/queue.v1.min.js"></script> | |
<script> | |
var width = 760, | |
height = 350, | |
legend_x = 85, | |
legend_y = 95; | |
// AlbersUsa scale:5600, translate:-450, 250 | |
var projection = d3.geo.mercator() | |
.scale(29100) | |
.translate([7310, 3500]); | |
var path = d3.geo.path() | |
.projection(projection); | |
var threshold = d3.scale.threshold() | |
.domain([20000, 65000]) | |
.range([1, 2, 3]); | |
window.threshold = threshold; | |
var legends = [ | |
{y: 245, tier: 'tier-3', legend: "65,000 people or more"}, | |
{y: 222, tier: 'tier-2', legend: "20,000 to 64,999 people"}, | |
{y: 199, tier: 'tier-1', legend: "Less than 20,000 people"} | |
] | |
window.legends = legends; | |
var q = queue() | |
.defer(d3.json, "KY-counties.json") | |
.defer(d3.csv, "KY-counties-pop.csv") | |
.await(ready); | |
function ready(error, counties, population) { | |
window.error = error; | |
window.counties = counties; | |
window.population = population; | |
if (error) throw error; | |
var popById = {}; | |
window.popById = popById; | |
population.forEach(function(d) { popById[d.id] = d.population; }); | |
var svg = d3.select("#KY-population").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
svg.selectAll("rect") | |
.data(legends) | |
.enter().append("rect") | |
.attr("x", legend_x) | |
.attr("y", function (d, i) { return (legend_y - (i * 23)); }) | |
.attr("height", 20) | |
.attr("width", 20) | |
.attr("class", function (d) { return d.tier + " legend"; }); | |
svg.selectAll("text") | |
.data(legends) | |
.enter().append("text") | |
.attr("x", function (d) { return legend_x + 25; }) | |
.attr("y", function(d, i) { return legend_y - i*23 + 15; }) | |
.attr("class", "description") | |
.text(function(d) { return d.legend; }); | |
svg.append("g") | |
.attr("id", "counties") | |
.selectAll("path") | |
.data(counties.features) | |
.enter().append("path") | |
.attr("class", function(d) { return "tier-" + threshold(popById[parseInt(d.properties.STATE + d.properties.COUNTY)]); }) | |
.attr("d", path); | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id | name | population | |
---|---|---|---|
21217 | Taylor County | 24512 | |
21121 | Knox County | 31883 | |
21071 | Floyd County | 39451 | |
21125 | Laurel County | 58849 | |
21035 | Calloway County | 37191 | |
21107 | Hopkins County | 46920 | |
21005 | Anderson County | 21421 | |
21097 | Harrison County | 18846 | |
21103 | Henry County | 15416 | |
21013 | Bell County | 28691 | |
21137 | Lincoln County | 24742 | |
21111 | Jefferson County | 741096 | |
21117 | Kenton County | 159720 | |
21227 | Warren County | 113792 | |
21015 | Boone County | 118811 | |
21101 | Henderson County | 46250 | |
21063 | Elliott County | 7852 | |
21233 | Webster County | 13621 | |
21019 | Boyd County | 49542 | |
21073 | Franklin County | 49285 | |
21051 | Clay County | 21730 | |
21129 | Lee County | 7887 | |
21157 | Marshall County | 31448 | |
21095 | Harlan County | 29278 | |
21053 | Clinton County | 10272 | |
21087 | Green County | 11258 | |
21171 | Monroe County | 10963 | |
21191 | Pendleton County | 14877 | |
21061 | Edmonson County | 12161 | |
21135 | Lewis County | 13870 | |
21139 | Livingston County | 9519 | |
21231 | Wayne County | 20813 | |
21169 | Metcalfe County | 10099 | |
21079 | Garrard County | 16912 | |
21075 | Fulton County | 6813 | |
21237 | Wolfe County | 7355 | |
21109 | Jackson County | 13494 | |
21205 | Rowan County | 23333 | |
21127 | Lawrence County | 15860 | |
21181 | Nicholas County | 7135 | |
21183 | Ohio County | 23842 | |
21187 | Owen County | 10841 | |
21185 | Oldham County | 60316 | |
21215 | Spencer County | 17061 | |
21153 | Magoffin County | 13333 | |
21007 | Ballard County | 8249 | |
21115 | Johnson County | 23356 | |
21089 | Greenup County | 36910 | |
21141 | Logan County | 26835 | |
21151 | Madison County | 82916 | |
21123 | Larue County | 14193 | |
21143 | Lyon County | 8314 | |
21179 | Nelson County | 43437 | |
21085 | Grayson County | 25746 | |
21017 | Bourbon County | 19985 | |
21093 | Hardin County | 105543 | |
21057 | Cumberland County | 6856 | |
21173 | Montgomery County | 26499 | |
21161 | Mason County | 17490 | |
21145 | McCracken County | 65565 | |
21229 | Washington County | 11717 | |
21043 | Carter County | 27720 | |
21003 | Allen County | 19956 | |
21219 | Todd County | 12460 | |
21011 | Bath County | 11591 | |
21049 | Clark County | 35613 | |
21083 | Graves County | 37121 | |
21039 | Carlisle County | 5104 | |
21091 | Hancock County | 8565 | |
21223 | Trimble County | 8809 | |
21029 | Bullitt County | 74319 | |
21225 | Union County | 15007 | |
21065 | Estill County | 14672 | |
21167 | Mercer County | 21331 | |
21105 | Hickman County | 4902 | |
21133 | Letcher County | 24519 | |
21193 | Perry County | 28712 | |
21177 | Muhlenberg County | 31499 | |
21067 | Fayette County | 295803 | |
21199 | Pulaski County | 63063 | |
21069 | Fleming County | 14348 | |
21077 | Gallatin County | 8589 | |
21235 | Whitley County | 35637 | |
21037 | Campbell County | 90336 | |
21201 | Robertson County | 2282 | |
21239 | Woodford County | 24939 | |
21195 | Pike County | 65024 | |
21055 | Crittenden County | 9315 | |
21119 | Knott County | 16346 | |
21197 | Powell County | 12613 | |
21165 | Menifee County | 6306 | |
21001 | Adair County | 18656 | |
21031 | Butler County | 12690 | |
21045 | Casey County | 15955 | |
21131 | Leslie County | 11310 | |
21009 | Barren County | 42173 | |
21163 | Meade County | 28602 | |
21025 | Breathitt County | 13878 | |
21207 | Russell County | 17565 | |
21203 | Rockcastle County | 17056 | |
21211 | Shelby County | 42074 | |
21047 | Christian County | 73955 | |
21027 | Breckinridge County | 20059 | |
21221 | Trigg County | 14339 | |
21021 | Boyle County | 28432 | |
21113 | Jessamine County | 48586 | |
21041 | Carroll County | 10811 | |
21099 | Hart County | 18199 | |
21189 | Owsley County | 4755 | |
21213 | Simpson County | 17327 | |
21147 | McCreary County | 18306 | |
21155 | Marion County | 19820 | |
21081 | Grant County | 24662 | |
21149 | McLean County | 9531 | |
21209 | Scott County | 47173 | |
21175 | Morgan County | 13923 | |
21023 | Bracken County | 8488 | |
21059 | Daviess County | 96656 | |
21159 | Martin County | 12929 | |
21033 | Caldwell County | 12984 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment