• I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

    See post explaining how and why I’m doing this.

    Code Learning:

    Three Takeways

    Chapter 3 Data-Driven Design and Interaction
    • Example of a chained transition to improve legibility of data viz: p 86
          teamG
               .append(“circle”).attr(“r”, 0)
               .transition()
               .delay(function(d, i) { return i * 100})
               .duration(500)
               .attr(“r”, 40)
               .transition()
               .duration(500)
               .attr(“r”, 20);
    • Getting access to DOM elements in a selection can be accomplished in two ways
      • Using the .node() function
      • Using the this in the inline functions
    • “Inline functions always have access to the DOM element along with the data point and array positioning of that data point in the bound data.  The DOM element, in this case, is represented by this.  We can see it in action using the .each() function of a selection, which performs the same code for each element in a selection.” p 86

    Reading and Learning Data Visualization Theoretically/Critically:

    Edward Tufte Visual Display of Quantitative Information

    Chapter Four Theory of Data Graphics
    Three Takeaways
    • “Bilateral symmetry doubles the space consumed by the design in a graphic, without adding new information.” p 97
    • “Redundancy, upon occasion, has its uses: giving a context and order to complexity, facilitating comparisons over various parts of the data, perhaps creating an aesthetic balance.” p 98
    • Five principles of theory of data graphics
      • Above else show the data
      • Maximum the data-ink ratio
      • Erase non-data-ink
      • Erase redundant data-ink
      • Revise and edit p 105
  • I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

    See post explaining how and why I’m doing this.

    Code Learning:

    Three Takeways

    Chapter 3 Data-Driven Design and Interaction
    • Don’t forget to assign your selections to a variable to refer to it so your code is more clean without having to type out d3.selectAll() every time p 81
      • var teamG = d3.selectAll(:g.overallG”);
    • “Although you might write an application entirely with D3 and your own custom code, for large-scale sustainable projects you’ll have to integrate more external libraries” p 82
    • Example of Event
      • var dataKeys = d3.keys(incomingData[0].function(el) {
        return el != “team” && el != “region”;
        }); // use d3.keys and pass it one of the objects from our array. d3.keys function returns the names of attributes of an objet as an array. The array is filtered to remove team and region attributes because they’re nonnumerical data that won’t be suitable for buttonClick functionality.
        d3.select(“#controls”).select(“button.teams”)
        .data(dataKeys).enter() // builds buttons based on the numerical data
        .append(“button”)
        .on(“click”, buttonClick) // registers onclick behavior for reach button, whith a wrapper that gives access to the data the at was bound to it when it was created
        .html(function(d) { return d;}) // remember dataKeys consists of an array of attribute names, so the d corresponds to one of those names and makes a good button title

        function buttonClick(datapoint) {
        var maxValue = d3.max(incomingData, function(d)
        return parseFloat(d[datapoint])}
        }); // function each button is calling on click, with the bound data sent automatically as the first argument

        var radiusScale = d3.scale.linear()
        .domain([0, maxValue]).range([2, 20]);

        d3.selectAll(“g.overallG”).select(“circle”)
        .attr(“r”, function(d) {
        return radiusScale(d[datapoint]);
        })
        }; // initial button click function sizes circles based on numerical value of each associated attribute

        // changing color on hoverover and back on mouseout

        teamG.on(“mouseover”, highlightRegion);
        function highlightRegion(d) {
        d3.selectAll(“g.overallG”).select(“cirlce”)
        .style(“fill”, function(p) {
        return p.region == d.region ? “red”: “gray”;
        });
        };

        teamG.on(“mouseout”, function() {
        d3.selectAll(“g.overallG”).select(“cirlce”).style(“fill”, “pink”);
        });

        teamG.on(“mouseout”, function() {
        d3.selectAll(“g.overallG”.select(“circle”).style(“fill”, “pink”);
        });

    Reading and Learning Data Visualization Theoretically/Critically:

    Edward Tufte Visual Display of Quantitative Information

    Chapter Three Sources of Graphical Integrity and Sophistication

     Three Takeaways
    • “If the statistics are boring, then you’ve got the wrong numbers.  Finding the right numbers requires as much specialized skill – statistical skill- and hard work as creating a beautiful design or covering a complex news story.” p 80
    • “The conditions under which many data graphics are produced- the lack of substantive and quantitative skills of the illustrators, dislike of quantitative evidence, and contempt for the intelligence of the audience- guarantee graphic mediocrity.  These conditions engender graphics that (1) lie; (2) employ only simplest designs, often unstandardized time-series based on a small handful of data points; and (3) miss the real news actually in the data” p 87
    • “Graphical competence demands three quite different skills: the substantive, statical, and artistic.” p 87
  • I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

    See post explaining how and why I’m doing this.

    Code Learning:

    Three Takeways

    Chapter Six Network Visualization

    • Example of function for adding new nodes and edges to make sure they’re connected to new network (note seems inefficient, why not just add it to data?  Good code practice/explanation tho)
      • function addNodesAndEdges() {
        • force.stop();
        • var oldEdges = force.links()
        • var oldNodes = force.nodes()
        • var newNode1 = {id: “raj”, followers: 100, following: 67};
        • var newNode2= {id: “wu”, followers: 50, following: 30};
        • var newEdge1 = {source: oldNodes[0], target: newNode1, weight 5};
        • var newEdge2 = {source: oldNodes[0], target newNode2, weight: 5};
        • oldEdges.push(newEdge1, newEdge2);
        • oldNodes.push(newNode1, newNode2);
        • force.links(oldEdges).nodes(oldNodes);
      • d3.select(“svg”).selectAll(“line.link”)
        • .data(oldEdges, function(d) {
        • return d.source.id + “-” + d.target.id
        • })
      • .enter()
      • .insert(“line”, “g.node”)
      • .attr(“class”, “link”)
      • .style(“stroke”, “red”)
      • .style(“stroke-width”,  5)
      • .attr(“marker-end”, “url(#Triangle)”);
    • var nodeEnter = d3.select(“svg”).selectAll(“g.node”)
      • .data(oldNodes, function(id) {
        • return d.id
        • }).enter()
        • .append(“g”)
        • .attr(“class”, “node”)
        • call(force.drag());
    • nodeEnter.append(“circle”)
      • .attr(“r”, 5)
      • .style(“fill”, “red”)
      • .style(“stroke”, “darkred”)
      • .style(“stroke-width”, “2px”)
    • nodeEnter.append(“text”)
      • .style(“text-anchor”, “middle”)
      • .attr(“y”, 15)
      • .text(function(d) { return d.id;});
      • force.start();
      • };
    • Force layouts are extremely resource intensive.  You can optimize by limiting the nodes on your network. p 202
    • Another way to optimize is use force.chargeDistance() to set max distance – the lower the charge distance, the less structured the layout will be, but the faster it will run. p 203

    Reading and Learning Data Visualization Theoretically/Critically:

    Edward Tufte Visual Display of Quantitative Information

    Chapter Two Graphical Integrity
    Three Takeaways
    • “At the core of the preoccupation with deceptive graphics was the assumption that data graphics were mainly devices for showing the obvious to the ignorant.  It is hard to imagine any doctrine more likely to stifle intellectual progress in a field” p 53
    • “Show data variation, not design variation” p 61
    • “In time-series display of money, deflated and standardized units of monetary measurement are nearly always better than nominal units” p 68
  • I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

    See post explaining how and why I’m doing this.

    Code Learning:

    Three Takeways

    Chapter 2 Information Visualization Data Flow

    • SGV text by default is anchored at start – right of initial position.  If you want to draw it different, set “text-anchor” style to “end” or “middle” p72
    • Child elements gain initial positions from parents, but it is drawn from the position according to rules from the element p 72
    • Don’t rely on array position as binding key.  Use something such as value of the data object or something meaningful p 74

    Chapter 6 Network Visualization

    • “One effective interaction technique is to set a node as fixed when the user interacts with it.  This allows users to drag nodes to a position on the canvas so they can visually sort the important nodes” p 196
      • d3.selectAll(“g.site”).on(“click”. fixNode);
      • function fixNode(d) {
        • d3.select(this).select(“circle”).style(“stroke-width”, 4); // add thicker width to style
        • d.fixed = true;
        • }
    • To filter a network, you need to stop() it, remove any nodes and links that are no longer part of the network, rebind those arrays to the force layout, and then start() the layout.  This can be done as a filter on the array that makes up your nodes” p 197
    • “By using the .indexOf function of an array, though, we can easily create our filtered links by checking to see if the source and target are both in our filtered nodes array.  Because we used key values when we first bound our arrays to our selection, we can use the selection.exit() to behavior to easily update our network” p 197
      • function filterNetwork() {
        • force.stop()
        • var originalNodes = force.nodes()
        • var originalLinks = force.links()// Accesses the current array of nodes and array of links associated with the force layout
        • var influentialNodes = originalNodes.filter(function (d) {
          • return d.followers > 20;
          • });
        • var influentialLinks = originalLinks.filter(function (d) {
          • return influentialNodes.indexOf(d.source) > -1 &&
          • influential Nodes.indexOf(d.target) > -1; // makes an array of links only out of those that reference existing nodes
          • });
      • d3. selectAll(“g.node”)
        • .data(influentialNodes, function(d) { return d.id}
        • .exit()
        • .transition()  // setting a transition on the .exit(), it applies the transition only to those nodes being removed and waits until the transition is finished to remove them
        • .duration(4000)
        • .style(“opacity”, 0)
        • .remove();
      • d3.selectAll(“line.link”)
        • .data(influentialLinks, function(d) {
          • return d.source.id + “-” + d.target.id;
        • })
        • .exit()
        • .transition()
        • .style(“opacity”, 0)
        • .remove();
        • force
          • .nodes(influentialNodes)
          • .links(influentialLinks);
        • force.start();
      • };

     

    Reading and Learning Data Visualization Theoretically/Critically:

    Edward Tufte Visual Display of Quantitative Information

    Chapter Two Graphical Integrity
    Three Takeaways
    • “At the core of the preoccupation with deceptive graphics was the assumption that data graphics were mainly devices for showing the obvious to the ignorant.  It is hard to imagine any doctrine more likely to stifle intellectual progress in a field” p 53
    • “Show data variation, not design variation” p 61
    • “In time-series display of money, deflated and standardized units of monetary measurement are nearly always better than nominal units” p 68
  • I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

    See post explaining how and why I’m doing this.

    Reading and Learning Data Visualization Theoretically/Critically:

    Edward Tufte Visual Display of Quantitative Information

    Chapter One Graphical Excellence
    • Pair small multiples with other information, e.g. a map to give more context – example of a map of socal and 3d view of pollutants p 42
    • “Indeed, in modern scientific literature, about 40 percent of published graphics have a relational form, with two or more variables (none of which are latitude, longitude, or time.  This is no accident, since the relational graphic- in its barest form, the scatterplot and its variants- is the greats of all graphical designs.  It links at least two variables, encouraging and even imploring the viewer to assess the possible causal relationship between the plotted variables” p 47
    • “Graphical excellence is that which gives to the viewer the greatest number of ideas in the shortest time with the least ink in the smallest space.  Graphical excellence is always multivariate.  And graphic excellence requires telling the truth about the data” p 51 (example of Minard’s graphic of the fate of Napoleon’s Army)
  • I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

    See post explaining how and why I’m doing this.

    Three Takeways

    Chapter 2 Information Visualization Data Flow

    • “You use selection.enter() to define how you want to create new elements based on the data you’re working with, and you use selection.exit() to define how you want to remove existing elements in a selection when the data that corresponds to them has been deleted” p 70
    • If you want to show a shape based on newly created data and we want them to have labels, we need to append <g> elements and not shapes to the <svg> canvas in initial selection.  Because data is bound to elements, we can use same syntax when you add child elements” p 71
    • Example of creating scatterplot using tweets data
    • d3.json(“tweets.json”,function(error,data) {dataViz(data.tweets)});
      • function dataViz(incomingData) {
        • incomingData.forEach(function (el) {
          • el.impact = el.favorites.length + el.retweets.length // creates an impact score by totalling the number of favorites and retweets
            el.tweetTime = new Date(el.timestamp);
            })
            var maxImpact = d3.max(incomingData, function(el) {return el.impact});
            var startEnd = d3.extent(incomingData, function(el) {return el.tweetTime}); // returns the earliest and latest times for a scale
            var timeRamp = d3.time.scale().domain(startEnd).range([20,480]); // start end is an array
            var yScale = d3.scale.linear().domain([0,maxImpact]).range([0,460]);
            var radiusScale = d3.scale.linear().domain([0,maxImpact]).range([1,20]);
            var colorScale = d3.scale.linear().domain([0,maxImpact]).range([“white”,”#990000″]); // builds a scale that maps impact to a ramp from white to dark red

            d3.select(“svg”)
            .selectAll(“circle”)
            .data(incomingData)
            .enter()
            .append(“circle”)
            .attr(“r”, function(d) {return radiusScale(d.impact)}) // size, color, and vertical postion will all be based on impact
            .attr(“cx”, function(d,i) {return timeRamp(d.tweetTime)})
            .attr(“cy”, function(d) {return 480 – yScale(d.impact)})
            .style(“fill”, function(d) {return colorScale(d.impact)})
            .style(“stroke”, “black”)
            .style(“stroke-width”, “1px”)
            }

    Chapter 6 Network Visualization

    •  Nodes that are more connected to each other than rest of network is known as modularity.  Nodes that are interconnected is known as clustering.  Clique is a term for a group of nodes that are fully connected to each other p 193
    • Charge sets the rate which nodes push other away, usually negative.  You could set them to positive if you wanted your nodes to exert an attract force.  p 193
    • Canvas gravity pulls all nodes toward center of layout.  llinkDistnace properity is the attraction betweeen the nodes – optimal distance between connected nodes.  p 193-194
  • I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

    See post explaining how and why I’m doing this.

    Three Takeways

    Chapter 2 Information Visualization Data Flow

    • Selections and data – think of sequence of load-> Format -> Measure- > Create -> Update p 57
    • “The .insert() function is a sister function to .append(), but .insert() gives you control over where in the DOM you add the new element.  You can also perform an append or insert directly on a selection, which adds one DOM element of the kind you specify for each DOM element in your selection.” p 59
    • “‘Multivariate’ is another way of saying that each data point has multiple data characteristics” p 67

    Chapter 6 Network Visualization

    • Degree is degree centrality refers to the total number of links that are connected to a node.  Degree is rough measure of importance of node in a network – weighted degree is the total value of connections to a node p 192
    • “Everytime you start the force() layout, D3 computes the total number of links per node, and updates that node’s weight attribute to reflect that” p 192
    • Eg adding a button that re-sizes nodes based on weight attribute:
      • d3.select(‘#controls”).append(“button”)
        • .on(“click”, sizeByDegree).html(“Degree Size”);
      • function sizeByDegree() {
        • force.stop();
        • d3.selectAll(“circle”)
          • .attr(“r”, function(d) { return d.weight * 2; });
          • };

    Reading and Learning Data Visualization Theoretically/Critically:

    Edward Tufte Visual Display of Quantitative Information

    Chapter One Graphical Excellence
    Three Takeaways
    • Think about ability to do parallel series using different visual encodings, eg chart of wheat p 34
    • “The problem with time-series is that the simple passage of time is not a good explanatory variable: descriptive chronology is not casual explanation” p 37
    • “An especially effective device for enhancing the explanatory power of time-series displays is to add spatial dimensions to the design of the graphic, so that the data are moving over space (in two or three dimensions) as well as over time. -> space-time-story graphics as an example with weighted time series lines and descriptors p 41
  • I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

    See post explaining how and why I’m doing this.

    Code Learning:

    Three Takeways

    Chapter 2 Information Visualization Data Flow

    • You can sort quantitative data into categories by putting values in a range or binning them.
    • For example if you use d3.scale.quantile() you can use the .range() setting to specify number of parts and labels.  There will be no error if you have a mismatch between number of .domain() values and .range() values because it autosorts and bins the value in domains to the number of values in range.
      • d3.scale.quantile().domain(samplearray).range([“small”, “medium”, “large”]);
      • d3.scale.quantile().domain(sampleArray).range([0, 1, 2])
    • d3.nest() can use shared attributes of data and sort them into discrete categories and subcategories.  The example below combines tweets into arrays under new objects labeled with user attributes
      • d3.json(“tweets.json”, function(data) {
        • var tweetData = data.tweets;
        • var nestedTweets = d3.nest()
          • .key(function(el) { return el.user })
          • .entries(tweetData);
        • });
    • When you have arrays you’ll want to size and position attributes based on values in the array.  Below are common ways to determine distribution
      • d3.min(testArray, function(d) { return d});
      • d3.max
      • d3.mean
      • d3.extent // returns min and max
    Chapter 6 Network Visualization
      • Directions of edges can also be represented using curved edges or edges that grow fatter on one end to another.  “To do something like that, you’d need to use a <path> rather than a <line> for the edges like we did with the Sankey layout or the arc diagram. “p 189
      • “If you think a force-directed layout is hard to read, you can pair it with another network visualization, such as an adjacency matrix, and highlight both as the user navigates either visualization” p 190
      • Weight is the strength of connection between two nodes.  The nodes in the system that are more mportant than others is referred to as centrality.  p 191

      190

    Reading and Learning Data Visualization Theoretically/Critically:

    Edward Tufte Visual Display of Quantitative Information

    Chapter One Graphical Excellence
    Three Takeaways
    • Stacking of multiple time series from Voyager 2 allowed comparing of multiple intensities p 29
    • “Time-series displays are at their best for big data sets with real variability.  Why waste the power of data graphics on simple linear changes, which can usually be better summarized in one or two numbers?” p 30
    • Combination of NYC weather for 1980 with time series, trend lines, bar charts, and area charge shows multiple narratives of one story effectively p 30
  • I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

    See post explaining how and why I’m doing this.

    Code Learning:

    Udacity Data Visualization and D3.js DimpleJS lectures

    • Example of chained use -> every two years in tick marks
      • var time_axis = d3.svg.axis()
        • .scale(time_scale)
        • .ticks(d3.time.years, 2)
    • Think of the ‘g’ element in svg as a div – an invisible fence around other svg objects. eg
      • d3.select(“svg”)
        • .append(‘g’)
        • .attr(‘class’, ‘x axis’)
        • .attr(‘transform’, “translate(0,” + height + “)”) // moves everything in to coordinates
        • .call(time_axis)
    • Use anonymous accessor function to find min and max of a column
      • var count_extent  = d3.extent(data, function (d) { return d[‘attendance’];
      • }); // pulls bound data
  • I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

    See post explaining how and why I’m doing this.

    Code Learning:

    Udacity Data Visualization and D3.js DimpleJS lectures

    • + is called unary operator that converts into numeric form
    • Use debugger to view data transformations, eg. looking at d, d[‘date’], d.attendance, and you can also use booleans to check types
    • Example of date and string transformation:
      • d3.tsv(“world_cup_geo.tsv”, function(d) {
        • d[‘date’] = format.parse(d[‘date’]);
        • d[‘attendance’] = +d[“attendance”];
        • return d; }, draw);