Giter Site home page Giter Site logo

Comments (10)

scotthmurray avatar scotthmurray commented on August 18, 2024

@jackparmer so they are! I'll correct this for the 2nd edition of the book. Let me know if you notice any others that are incorrect.

In the meantime, note discussion in the book about the importance of manually verifying geocoder results (which I did not do here). :)

from d3-book.

ExtremelySeriousChicken avatar ExtremelySeriousChicken commented on August 18, 2024

Hey I noticed that most of the cities in the map has incorrect location (at least when I downloaded the content and tried the examples). For example, Chicago is not in Illinous, San Francisco is in Florida, etc. May I know if this only happens in my case? Thanks! ^u^

from d3-book.

jackparmer avatar jackparmer commented on August 18, 2024

I used this:
https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv

For this map:
https://plot.ly/python/bubble-maps/

Feel free to use if helpful!

from d3-book.

scotthmurray avatar scotthmurray commented on August 18, 2024

@ExtremelySeriousChicken some of the values are a bit off, but it shouldn't be that bad. Can you post a screenshot?

@jackparmer thank you!

from d3-book.

ExtremelySeriousChicken avatar ExtremelySeriousChicken commented on August 18, 2024

image

from d3-book.

ExtremelySeriousChicken avatar ExtremelySeriousChicken commented on August 18, 2024

image

from d3-book.

ExtremelySeriousChicken avatar ExtremelySeriousChicken commented on August 18, 2024

Here is the full code of the script part of the page...

        //Width and height
        var w = 500;
        var h = 300;

        //Define map projection
        var projection = d3.geo.albersUsa()
                               .translate([w/2, h/2])
                               .scale([500]);

        //Define path generator
        var path = d3.geo.path()
                         .projection(projection);

        //Define quantize scale to sort data values into buckets of color
        var color = d3.scale.quantize()
                            .range(["rgb(237,248,233)","rgb(186,228,179)","rgb(116,196,118)","rgb(49,163,84)","rgb(0,109,44)"]);
                            //Colors taken from colorbrewer.js, included in the D3 download

        //Create SVG element
        var svg = d3.select("body")
                    .append("svg")
                    .attr("width", w)
                    .attr("height", h);

        //Load in agriculture data
        d3.csv("us-ag-productivity-2004.csv", function(data) {

            //Set input domain for color scale
            color.domain([
                d3.min(data, function(d) { return d.value; }), 
                d3.max(data, function(d) { return d.value; })
            ]);

            //Load in GeoJSON data
            d3.json("us-states.json", function(json) {

                //Merge the ag. data and GeoJSON
                //Loop through once for each ag. data value
                for (var i = 0; i < data.length; i++) {

                    var dataState = data[i].state;              //Grab state name
                    var dataValue = parseFloat(data[i].value);  //Grab data value, and convert from string to float

                    //Find the corresponding state inside the GeoJSON
                    for (var j = 0; j < json.features.length; j++) {

                        var jsonState = json.features[j].properties.name;

                        if (dataState == jsonState) {

                            //Copy the data value into the JSON
                            json.features[j].properties.value = dataValue;

                            //Stop looking through the JSON
                            break;

                        }
                    }       
                }

                //Bind data and create one path per GeoJSON feature
                svg.selectAll("path")
                   .data(json.features)
                   .enter()
                   .append("path")
                   .attr("d", path)
                   .style("fill", function(d) {
                        //Get data value
                        var value = d.properties.value;

                        if (value) {
                            //If value exists…
                            return color(value);
                        } else {
                            //If value is undefined…
                            return "#ccc";
                        }
                   });

                //Load in cities data
                d3.csv("us-cities.csv", function(data) {

                    svg.selectAll("circle")
                       .data(data)
                       .enter()
                       .append("circle")
                       .attr("cx", function(d) {
                           return projection([d.lon, d.lat])[0];
                       })
                       .attr("cy", function(d) {
                           return projection([d.lon, d.lat])[1];
                       })
                       .attr("r", function(d) {
                            return Math.sqrt(parseInt(d.population) * 0.00004);
                       })
                       .style("fill", "yellow")
                       .style("opacity", 0.75)
                       .append("title")
                       .text(function(d){
                           return d.place + ":" + d.population;
                       });

                });


            });

        });

from d3-book.

scotthmurray avatar scotthmurray commented on August 18, 2024

Oh, you’re right! This is really bad, and must have been the result of me sorting the place names independently of lat/lon values. I’ll fix this, thanks.

from d3-book.

JaimeStill avatar JaimeStill commented on August 18, 2024

All, I updated the values using geocaching. Just change from .txt to .csv.
fixed points
us-cities.txt

from d3-book.

scotthmurray avatar scotthmurray commented on August 18, 2024

Thank you all very much for reporting this (huge) oversight on my part.

I've corrected the data for the 2nd edition of the book. Thanks!

from d3-book.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.