If we were working with d3 v5, how might we go about coloring nodes based on their degrees? It's important that the visualization clearly shows nodes with higher degrees in darker shades and nodes with lower degrees in lighter shades.
I attempted to implement the following solution, but unfortunately it did not produce the desired outcome:
// To assign colors based on node degree
var colorScale = d3.scaleOrdinal()
.domain([1, 5]) // defining the range of node degrees
.range(["#fbb4ae", "#b3cde3", "#ccebc5", "#decbe4", "#fed9a6"]); // specifying the color range
// Creating a selection for nodes and binding data
var node = svg.append("g")
.attr("class", "nodes")
.selectAll("circle")
.data(nodes)
.enter().append("circle")
.attr("r", 5)
.style("fill", function(d) { return colorScale(d.degree); });
// Using the defined color scale to color the nodes