CS 725/825 - Spring 2018 - Homework 3 - Bar Chart
Hussam Hallak
1. What is the type of mark used in the bar chart?
2. List the channels, the attribute they are mapped to, and the data type of that attribute.
Answer:
The bar chart encodes two attributes using a line mark with the vertical spatial position channel for the quantitative attribute, letter usage frequency, and the horizontal spatial position channel for the categorical attribute, the letter itself. The letter data type is an item since each letter is an individual entity that is discrete. The letter frequency data type is an attribute, which is some specific property that can be measured, observed, and logged.
Edit the top chart to use the color hue channel to express the letter attribute. You will need to look at the d3 Color Scales links on the class Links page. Hint: This isn't a one-line change -- you have to setup a color scale and then apply it to the bars based on the appropriate value.
I Edited the top chart and was able to setup a color scale and use the color hue channel to express the letter attribute and applied it to the bars based on the appropriate value.
First, define a variable color
and assign a color scale to it:
var color = d3.scaleOrdinal(d3.schemeCategory20);
Then, change the fill color for the bars from steelblue and make it a function of the data and use the letter part of the data d
to color the bar.
I can show you better than I can tell you. Basically change this line:
.style("fill", "steelblue") // color of the bars
to this:
.style("fill", function(d) { return color(d.letter);}) // color of the bars
3. After your changes, list the channels, the attribute they are mapped to, and the data type of that attribute.
Answer
The bar chart still encodes two attributes using a line mark with the vertical spatial position channel for the quantitative attribute, letter usage frequency, and two channels categorical attribute, the letter itself, the horizontal spatial position and color hue. The letter data type is an item since each letter is an individual entity that is discrete. The letter frequency data type is an attribute, which is some specific property that can be measured, observed, and logged. The question is: Did we add any useful information by doing this? The answer is NO! This is because these different colors do not group letters together based on their frequency. We are confusing the viewer, who might think that these colors mean something, but they do not.
Edit the bottom chart to use the color saturation channel to express the frequency attribute.
We can similarly do that by adding this line of code first to define a color2
variable and set it to light blue
var color2 = d3.color("lightblue");
Then we add the following lines to map into the data and return the frequency. Then find the maximum and minimum value to construct a multiplier that will make the saturation clear. This step is the hardest because it requires playing with the number until we get the best multiplier. Ideally, we need to normalize the frequency, but this multiplier gave good results.
var dataVals = data.map(function(e) {return e.frequency});
var minVal = d3.min(dataVals);
var maxVal = d3.max(dataVals);
var multiplier = 11/(maxVal-minVal);
Now it's time to use the multiplier and the frequency and return their product to pass to the function darker(k)
. I initially passed the raw frequency in the function darker()
but the saturation barely changed because the values are so small. In the beginning, I thought my code was wrong, but it turned out that the code needs some tweaking to fit this kind of data.
.style("fill", function(d) { return d3.hsl(color2).darker(d.frequency * multiplier);}) // color of the bars
The darker the color, the more frequenct the letter is used, and the longer the bar.
4. After your changes, list the channels, the attribute they are mapped to, and the data type of that attribute.List all of the channels mapped to the frequency attribute.
Answer
The bar chart still encodes two attributes using a line mark, but with two channels, the vertical spatial position channel and color saturation channel for the quantitative attribute, letter usage frequency, and one channels categorical attribute, the letter itself, the horizontal spatial position. The letter data type is an item since each letter is an individual entity that is discrete. The letter frequency data type is an attribute, which is some specific property that can be measured, observed, and logged. Adain, did we add any useful information by doing this? The answer is NO! This is because these different shades of the same color repeat the same information projected by the length of the bars. This situation would be ideal if we are short on space and cannot afford to put a bar chart. In that case we can make all the bars short (squares) and use the color saturation to give information about the frequency. This time color saturation groups letters together based on their frequency. Again, We are confusing the viewer without adding any new information.
https://d3js.org/d3.v4.min.js
https://d3js.org/d3-scale-chromatic.v1.min.js