class:inverse <br><br><br> ## Data Communication ### DSC365: Introduction to Data Science #### September 15, 2026 --- ## Announcements - Lab 3: Due tonight -- if you would like extra time (so you can finish MP 1), let me know - **Mini-Project 1** + Please update the data sets page! + Due **Thursday September 17, 2026 at 1:59 pm (i.e. before class starts)** + Presentations during class that day --- class:inverse <br> <br> <br> <br> <br> <br> <br> <br> <br> .center[ ## Graphical Perception ] --- ### Graphical Perception To visually display data, information is encoded into a graph. The viewer then visually decodes this information, known as graphical perception, to gain knowledge. In previous weeks we have discussed how to choose the right plot to visualize the data. This week we will focus on the other design choices to aid in graphical perception --- ### Keep it Simple A general guideline is to use simplicity in the design. --- ### Show the Data Clearly **Goal**: display the relationship between the average lifespan and lifespan standard deviation of different countries by labeling each point by sex and education level. Countries are represented by each point, with the country names also appearing .pull-left[ <!-- Trigger the Modal --> <img id='imguncleargraph' src='images/unclear-graph.png' alt='Original plot that shows each observation on the same scatterplot, where different symbols are used to represent the differeng groups' =''> <!-- The Modal --> <div id='modaluncleargraph' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodaluncleargraph'> <!-- Modal Caption (Image Text) --> <div id='captionuncleargraph' class='modal-caption'></div> </div> ].pull-right[ <!-- Trigger the Modal --> <img id='imgbettergraph' src='images/better-graph.png' alt='Improved visualization that facets each scatterplot by country so can reduce the clutter problem from the original plot.' =''> <!-- The Modal --> <div id='modalbettergraph' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalbettergraph'> <!-- Modal Caption (Image Text) --> <div id='captionbettergraph' class='modal-caption'></div> </div> ] [(Source)](https://www.jstor.org/stable/24737226?seq=1) --- ### Show the Data Clearly: Preattentive Features Pre-attentive features "jump out" in under 500ms - Color, shape, angle - spatial location - movement There is a hierarchy of features: color is stronger than shape <br> <br> <br> <br> Articles: [Aricle 1](https://www.tandfonline.com/doi/full/10.1080/10618600.2016.1209116), [Article 2](https://www.sciencedirect.com/science/article/abs/pii/S0734189X85800049) --- class:primary ### Find the Target <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-5-1.png" alt="Plot of green triangles with one green circle to demonstrate the preattentive feature of shape." width="60%" height="60%" style="display: block; margin: auto;" /> ??? Find the target? how quickly did you spot the circle? --- class:primary ### Find the Target <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-6-1.png" alt="Plot of red circles with one green circle to demonstrate the preattentive feature of color." width="60%" height="60%" style="display: block; margin: auto;" /> --- class:primary ### Preattentive Features .pull-left[ **Shape/Color**: Dual-Encoded <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-7-1.png" alt="Demonstrates an example of a dual encoded plot, where each different group has a different shape and color." style="display: block; margin: auto;" /> ].pull-right[ **Shape/Color**: Separate Variables <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-8-1.png" alt="Demostrates an example with four groups of red circles, red trianges, green circles, and green triangles. Shows how it is difficult to quickly pick out the different groups." style="display: block; margin: auto;" /> ] --- ### Show Data Clearly: Pie Charts are Bad .pull-left[ <img src="data-viz-and-communication_files/figure-html/diamonds1-1.png" alt="Pie Chart of the diamonds dataset showing the frequency of each cut in the dataset." style="display: block; margin: auto;" /> ].pull-right[ <img src="data-viz-and-communication_files/figure-html/diamonds2-1.png" alt="Bar Chart of the diamonds dataset showing the frequency of each cut in the dataset." style="display: block; margin: auto;" /> ] Anything that can be put into a pie chart can also be put into a bar chart - Research has shown that people have more difficulty with angle measurements than length measurements [(paper)](https://www.jstor.org/stable/2288400?seq=1). --- ### Show Data Clearly: Color + Hue: the actual color (red, green, blue, etc.) <br> + Intensity: brightness <br> When choosing color schemes: + Want mappings from data to color that are not just numerically but also perceptually uniform + Distinguish between sequential scales and categorical scales + Be conscious of what color means <br> <br> [(source)](https://ieeexplore.ieee.org/document/773961) --- ### Color .center[Our eyes are optimized for perceiving the yellow/green region] <img src="images/color-spectrum.png" alt="Illustration of the color spectrum." width="60%" style="display: block; margin: auto;" /> --- ### Gradients Qualitative schemes: no more than 7 colors <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-10-1.png" alt="Example of a seven color qualitative color scheme." width="35%" height="35%" /> Quantitative schemes: use color gradient with only one hue for positive values <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-11-1.png" alt="Example of a single hue quantiative color gradient." width="35%" height="35%" /> Quantitative schemes: use color gradient with two hues for positive and negative values. Gradient should go through a light, neutral color (white) <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-12-1.png" alt="Example of a double hue quantiative color gradient where the colors transition through a neutral color of white." width="35%" height="35%" /> [(source)](https://www.zeileis.org/papers/Zeileis+Hornik+Murrell-2009.pdf) --- ### Color Blindness Not everyone perceives color in the same way. Some individuals have [colorblindness or color deficiencies](https://en.wikipedia.org/wiki/Color_blindness). You can take a test designed to screen for colorblindness [here](https://eyeque.com/color-blind-test/). Suggestions: + Design for a black-and-white photocopier + Colors + A monochromatic color gradient scheme where possible. + Suggested 2-color gradient: blue/purple - white - orange + Avoid: green-yellow-red signaling + The `viridis package` (from last week's lab) contains a set of color scales designed to span as wide a palette as possible. + [This website](https://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3) can help pick palettes as well + Utilize double encoding --- ### Example: Hair Color The data `HairEyeColor` provides information of hair eye colors in a statistics class. Suppose now we want to see the distribution of hair color in this class. .pull-left[ ``` r hairData %>% ggplot(aes(x=Hair, y=Freq)) + * geom_col(aes(color = Hair)) ``` <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-14-1.png" alt="Bar chart displaying the frequency of each hair color in the data set, where color equals hair is used to color the boundary of each bar." /> ].pull-right[ ``` r hairData %>% ggplot(aes(x=Hair, y=Freq)) + * geom_col(aes(fill = Hair)) ``` <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-15-1.png" alt="Bar chart displaying the frequency of each hair color in the data set, where fill equals hair is used to color in the area of each bar." /> ] --- ### Example: Hair Color It is a little weird that the color in the visualization does not match the color. Let’s try to define the color by ourselves. ``` r ggplot(hairData, aes(x = Hair, y = Freq)) + geom_col(aes(fill = Hair)) + * scale_fill_manual(breaks = c("Black", "Brown", "Red", "Blond"), * values=c("black", "brown", "red", "yellow")) ``` <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-16-1.png" alt="Bar chart displaying the frequency of each hair color in the data set, where we specify the specific colors for each bar." style="display: block; margin: auto;" /> --- ### Example: Hair Color You may have realized that in the previous figure, the color red and brown are pretty close. For an extreme case, what if you have a reader who is color-blind? There are a lot of [research](https://jfly.uni-koeln.de/color/) on which palette then to use. ``` r cbPalette <- c("#000000","#E69F00","#56B4E9","#009E73","#F0E442") ggplot(hairData, aes(x = Hair, y = Freq)) + geom_col(aes(fill = Hair)) + scale_fill_manual(values=cbPalette) ``` <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-17-1.png" alt="Bar chart displaying the frequency of each hair color in the data set, where we specify the specific colors for each bar using a color blind friendly pallette." style="display: block; margin: auto;" /> --- ### Try it for yourself!! Now try by yourself (or with a group) with another type of figure. (a). Use the `iris` data below. Plot the figure to show the relation between Sepal.Length and Petal.Length. ``` r data(iris) ``` (b). Use colors to distinguish the species. Which function you have used? fill or color? (c). Use red to represents `virginica`, blue to represents `versicolor`, and yellow to represents `setosa`. (d). Use the color blind friendly color to distinguish three different species (e). Besides of the color, use different shape of the points to represents the difference (Hint: Use Google or the Help Documentation). --- class:inverse <br> <br> <br> <br> <br> <br> <br> <br> <br> .center[ # Data Misrepresentation ] --- ### Common Ways to Misreprsent Data <br> <br> <br> <br> <br> <br> <br> <!-- Trigger the Modal --> <img id='imgcompgraphs' src='images/comp-graphs.png' alt='Illustration of the impact of misleading scales on interpretation of a bar chart.' =''> <!-- The Modal --> <div id='modalcompgraphs' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalcompgraphs'> <!-- Modal Caption (Image Text) --> <div id='captioncompgraphs' class='modal-caption'></div> </div> --- ### What's Wrong with These Plots? .pull-left[ <!-- Trigger the Modal --> <img id='imgbadpie' src='images/bad-pie.PNG' alt='Pie chart of how people voted for president in 2016.' width='90%'> <!-- Trigger the Modal --> <img id='imgbadcolor' src='images/bad-color.png' alt='Map of suicide rates by country with a bad color scheme.' width='85%'> <!-- The Modal --> <div id='modalbadpie' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalbadpie'> <!-- Modal Caption (Image Text) --> <div id='captionbadpie' class='modal-caption'></div> </div> <!-- The Modal --> <div id='modalbadcolor' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalbadcolor'> <!-- Modal Caption (Image Text) --> <div id='captionbadcolor' class='modal-caption'></div> </div> ].pull-right[ <!-- Trigger the Modal --> <img id='imgbadline' src='images/bad-line.PNG' alt='Line chart of Asian Hate Crime reports over time.' width='100%'> <!-- Trigger the Modal --> <img id='imgbadbar' src='images/bad-bar.png' alt='Bar Chart of Number of Covid-19 cases by country over time.' width='100%'> <!-- The Modal --> <div id='modalbadline' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalbadline'> <!-- Modal Caption (Image Text) --> <div id='captionbadline' class='modal-caption'></div> </div> <!-- The Modal --> <div id='modalbadbar' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalbadbar'> <!-- Modal Caption (Image Text) --> <div id='captionbadbar' class='modal-caption'></div> </div> ] --- ### Election Maps .pull-left[ <!-- Trigger the Modal --> <img id='imgelectionstate' src='images/election-state.png' alt='Election Map that colors in each state by which presidential nominees won that states electoral votes.' =''> <!-- Trigger the Modal --> <img id='imgelectionpop' src='images/election-pop.png' alt='Election Map that incorporates information about population.' =''> <!-- The Modal --> <div id='modalelectionstate' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalelectionstate'> <!-- Modal Caption (Image Text) --> <div id='captionelectionstate' class='modal-caption'></div> </div> <!-- The Modal --> <div id='modalelectionpop' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalelectionpop'> <!-- Modal Caption (Image Text) --> <div id='captionelectionpop' class='modal-caption'></div> </div> ].pull-right[ <!-- Trigger the Modal --> <img id='imgelectoral' src='images/electoral.png' alt='Election Map that displays the number of electoral votes each presidential candidate won as hexagons, where the hexagons are arranged in a similar shape as the United States.' =''> <!-- The Modal --> <div id='modalelectoral' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalelectoral'> <!-- Modal Caption (Image Text) --> <div id='captionelectoral' class='modal-caption'></div> </div> <br> <br> [Other Examples](https://www.flerlagetwins.com/2020/10/presidential-election.html) ] .center[ [Source 1](https://storymaps.arcgis.com/stories/427c500cfa5f459590671a8d060c4ab4) and [Source 2](https://medium.com/swlh/the-problem-with-election-maps-443b3a941dc7) ] --- ### Visualzing Uncertainty - Uncertainty is fundamental to data analysis and models - Effectively communicating uncertainty in visualization is hard and is still being researched. - Don't present the uncertainty information without describing what it means. .pull-left[ <!-- Trigger the Modal --> <img id='imgmeaninterval' src='images/mean-interval.png' alt='Visualization of a mean rating for different countries where confidence intervals are included to show uncertainty information.' =''> <!-- The Modal --> <div id='modalmeaninterval' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalmeaninterval'> <!-- Modal Caption (Image Text) --> <div id='captionmeaninterval' class='modal-caption'></div> </div> ].pull-right[ <!-- Trigger the Modal --> <img id='imghurricane' src='images/hurricane.png' alt='Visualization of different ways uncertainty information about hurricane paths can be incorporated onto a plot.' =''> <!-- The Modal --> <div id='modalhurricane' class='modal'> <!-- Modal Content (The Image) --> <img class='modal-content' id='imgmodalhurricane'> <!-- Modal Caption (Image Text) --> <div id='captionhurricane' class='modal-caption'></div> </div> ] --- class:inverse <br> <br> <br> <br> <br> <br> <br> <br> <br> .center[ # Writing about Visualizations ] --- ### Writing About Your Figure Your visualizations should include: - Clearly labeled axes - clear and descriptive captions - readable and easily understandable legends (if applicable) This is *in addition to* writing about the figure in the body of the report (more on this in a moment) <!-- - interpretation of the plot --> <!-- + "Figure 1 shows a positive trend between tree height on the x-axis and leaf size on the y-axis" --> <!-- - explain outliers --> <!-- + "The point in the upper left corner is the flooble tree, which is an exceptionally short tree with very large leaves" --> <!-- - contextualizing the figure --> <!-- + "From this we conclude that, in general, taller trees also have bigger leaves" --> --- ### Labels (a). Use plain English `\(\\\)` (b). If there is mathematically symbols in your label, use `expression`: ``` r x = -5:10 y = x^2 xy = data.frame(x,y) ggplot(xy, aes(x = x, y=y)) + geom_point() + * xlab("X") + ylab(expression(X^2)) ``` <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-25-1.png" alt="Scatterplot which utilizes the expression function to add an exponent to an axis label." style="display: block; margin: auto;" /> --- ### Captions There are two ways of writing a caption: 1). In-Figure Style (for screen readers, some browsers show as mouse-over text) Code chunk includes `fig.alt="Example of visualization created with ggplot where we added a title."` ``` r ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, group=Species)) + geom_point(aes(color = Species, shape = Species)) + xlab("Sepal Length") + ylab("Patal Length") + * ggtitle("Relation between Sepal Length and Petal Length") ``` <img src="data-viz-and-communication_files/figure-html/unnamed-chunk-26-1.png" alt="Example of visualization created with ggplot where we added a title." style="display: block; margin: auto;" /> --- ### Captions 2). Formal report style: use descriptive caption + It is not included in the figure. Usually placed below the figure. + Starts with the word “figure” or “table” followed by a number and a colon + One sentence to clearly explained What and How is being compared + One sentence to summarize the main conclusion. + Any other necessary context <img src="images/fig-caption.png" alt="Visualization showing how to create a figure caption using the code chunk options in quarto." width="2013" style="display: block; margin: auto;" /> **Note**: label not required, but can be useful for [cross-referencing](https://quarto.org/docs/authoring/cross-references.html) --- ### Captions What this then looks like: <img src="images/with-caption.png" alt="Visualization showing how a figure caption created within a code chunk in quarto outputs in the rendered document." width="2213" style="display: block; margin: auto;" /> --- ### Captions The caption only shows in the rendered version of documents. Why do we need a descriptive caption? - The figure can stand alone, allowing the reader How do we know we have written a good caption? - The reader can capture the main argument without actually seeing the figure This might seem counterintuitive, but all parts of your report, presentation, etc. work together to convey your message. --- ### Writing About Figures in Reports Once you generate one figures, here is what you should do: - Re-introduce the visualization and main argument - Cite any statistical evidence or figure characteristics to support your argument - State secondary argument and other information - Contrast with the other figures if necessary - Provide potential reasons and explain the conclusion --- ### Example: Writing About Figures in Reports Figure 2 indicates that there is no linear relationship between iris sepal width and petal width since the scatter plot did not show a clear linear shape on the distribution of the point. Meanwhile, the three species does have clear different distributions of the sepal width and petal width and within a species, the the sepal width and petal width may have a positive linear relationship except Setosa, which does not have a clear trend. The relative size of different iris species is similar to what we have found in Figure 1, where Virginica tends to have the largest size among all three while Setosa is the smallest. One of the potential reasons for the different sizes may be the habitat condition while Virginica tends to grow in the places with enough sunshine but Setosa prefers relatively dark and wet environment.