4.2 Reflections

Before getting our hands dirty — with code, rather than with paint — we briefly reflect on some ways of justifying and evaluating visualizations.

4.2.1 Why visualize?

An urge for visualizing data is not a new phenomenon. Although our ability for generating visualizations has greatly increased with the ubiquity of computers, people have always drawn sketches and diagrams for understanding natural and statistical phenomena (Friendly, 2008).

But why should we visualize data? Most people intuitively assume that visualizations help our understanding of data by illustrating or emphasizing certain aspects, facilitating comparisons, or clarifying patterns that would otherwise remain hidden. Precisely justifying why visualizations may have these benefits is much harder (see Streeb et al., 2019, for a comprehensive analysis). And it would be naive to assume that visualizations are always helpful or appropriate. Instead, we can easily think of potential problems caused by visualizations and claim that they frequently distract from important aspects, facilitate misleading comparisons, or obscure and hide patterns in data. Thus, visualizations are representations that can be good or bad on many levels. Creating effective visualizations requires a mix of knowledge and skills that include aspects of human perception, psychology, design, and technology.

An example

Whenever theoretical justifications are hard, we can use an example that proves the existence of cases in which visualizations help. The following code snippets define four R objects:

# Get 4 sets of data:
a_1 <- ds4psy::get_set(1)
a_2 <- ds4psy::get_set(2)
a_3 <- ds4psy::get_set(3)
a_4 <- ds4psy::get_set(4)

Each of these four objects provides a small data frame (containing 11 rows and 2 columns named x and y). The following functions allow us to examine object a_1:

# Inspect a_1:
a_1         # print object (data frame)
#>      x     y
#> p01 10  8.04
#> p02  8  6.95
#> p03 13  7.58
#> p04  9  8.81
#> p05 11  8.33
#> p06 14  9.96
#> p07  6  7.24
#> p08  4  4.26
#> p09 12 10.84
#> p10  7  4.82
#> p11  5  5.68
dim(a_1)    # a table with 11 cases (rows) and 2 variables (columns) 
#> [1] 11  2
str(a_1)    # see table structure
#> 'data.frame':    11 obs. of  2 variables:
#>  $ x: num  10 8 13 9 11 14 6 4 12 7 ...
#>  $ y: num  8.04 6.95 7.58 8.81 8.33 ...
names(a_1)  # names of the 2 column (variables) 
#> [1] "x" "y"

With some training in statistics, we might be tempted to summarize the values of both variables x and y (by computing their means or standard deviations), or assess their relationship to each other (as a correlation or linear regression). For the first set a_1, the corresponding values are as follows:

# Analyzing a_1:
mean(a_1$x)  # mean of x
#> [1] 9
mean(a_1$y)  # mean of y
#> [1] 7.500909

sd(a_1$x)    # SD of x
#> [1] 3.316625
sd(a_1$y)    # SD of y
#> [1] 2.031568

cor(x = a_1$x, y = a_2$y)  # correlation between x and y
#> [1] 0.8162365
lm(y ~ x, a_1)             # linear model/regression: y by x
#> Call:
#> lm(formula = y ~ x, data = a_1)
#> Coefficients:
#> (Intercept)            x  
#>      3.0001       0.5001

Rather than doing this only for a_1, we could examine all four sets in this way. Table 4.1 provides an overview of the corresponding summary statistics:

Table 4.1: Summary statistics of the four subsets (rounded to two decimals).
nr n mn_x mn_y sd_x sd_y r_xy intercept slope
1 11 9 7.5 3.32 2.03 0.82 3 0.5
2 11 9 7.5 3.32 2.03 0.82 3 0.5
3 11 9 7.5 3.32 2.03 0.82 3 0.5
4 11 9 7.5 3.32 2.03 0.82 3 0.5

What would we conclude from Table 4.1? Given that the means, standard deviations, correlations, and best fitting lines of a linear regression are identical, it is likely that we would assume that the underlying datasets are very similar or identical. Perhaps they even describe the same individuals, but are just presented in different orders?

As this is an example deliberately constructed to make a point, the likely conclusion turns out to be wrong. In fact, the datasets are not identical, but show some systematic differences. Importantly, this is easy to see when visualizing the raw data points. Figure 4.1 shows four scatterplots that show the x-y coordinates of each subset as points:

Scatterplots of the four subsets. (The \(+\)-symbol marks the mean of each set; blue lines indicate the best fitting linear regression line.)

Figure 4.1: Scatterplots of the four subsets. (The \(+\)-symbol marks the mean of each set; blue lines indicate the best fitting linear regression line.)

Inspecting the scatterplots of Figure 4.1 allows us to see what is going on here: The four sets differ in many aspects, but are constructed in a way that their summary statistics are identical. The data used in this particular example is known as Anscombe’s quartet (Anscombe, 1973) and is included in R as anscombe in the datasets package (R Core Team, 2021). (The get_set() function of ds4psy only extracts each subset as a data frame.)

More generally, Figure 4.1 illustrates that detecting and seeing similarities or differences crucially depends on the kinds of measures or visualization used: Whereas some ways of describing the data reveal similarities (e.g., means, or linear regression curves), others reveal differences (e.g., the distribution of raw data points).11

4.2.2 Evaluating visualizations

Having accepted that visualizations can be useful, we can shift our attention from justifying to judging visualizations. This raises an new issue:

  • How can we create good visualizations?

Although it is relatively simple to spot flaws or misleading elements in many visualizations, providing general principles for good visualizations is challenging.

The lack of formal theory bedevils good graphics.
The only way to make progress is through training in principles and through experience in practice.

(Unwin, 2008, p. 77)

Quite often, creating a visualization seems to proceed in a trial-and-error fashion. A data analyst starts by selecting some type of visualization and then adds and tweaks features until a satifying result is obtained.

The most salient (or “obvious”) features of graphs are their aesthetic properties:

  • colors
  • shapes
  • sizes and widths
  • endoding and file formats

Being an artificial object that is designed to serve particular purposes, good questions for evaluating a given visualization include:

  • What is the message and the audience for which this visualization was designed?
  • How does it convey its message? Which aesthetic features does it use? Which perceptual or cognitive operations does it require or enable?
  • How successful is it? Are there ways in which its functionality could be improved?

Thus, evaluating a visualization does not only depend on the visualization itself, but on its relation to the data, its message, and its audience.

A matter of ER: Match of a visualization to a particular task (message) and person (audience, viewer). Again, multiple levers for effecting change (e.g., design or training).

The good, the bad and the ugly

Often easier to detect and enumerate mistakes than to provide a set of principles that leads to good visualizations. Distinguish various ways of being bad.

Chartjunk and other crimes

Reduce non-data ink and chartjunk (see Wikipedia).

The term chartjunk was coined by Edward Tufte in his book The Visual Display of Quantitative Information (2001). Tufte wrote:

The interior decoration of graphics generates a lot of ink that does not tell the viewer anything new.
The purpose of decoration varies – to make the graphic appear more scientific and precise,
to enliven the display, to give the designer an opportunity to exercise artistic skills.
Regardless of its cause, it is all non-data-ink or redundant data-ink, and it is often chartjunk.

Edward R. Tufte (1983)

The notion is similar to Adolf Loos’s claim that — in architecture — ornament is a crime (see Wikipedia) and the design principle that form follows function (see Wikipedia).

4.2.3 Types of graphs

There are many different types of visualizations. Many compare or contrast values on one dimensions, other combine multiple variables.

Is there a taxonomy of visualizations by tasks and type of comparisons?

4.2.4 Plotting in base R

This chapter introduces base R graphics, rather than ggplot2, which is covered in Chapter 2: Visualizing data of the ds4psy textbook. Here, we distinguish between two general approaches for plotting:

  • Basic plots (Section 4.3) use pre-packaged plotting functions for specific visualizations:

    • Hands-on instructions on visualizing data in base R.
    • Distinguishing between different types of visualizations.
    • Adding aesthetics: Color, shape, size, etc.
  • Complex plots (Section 4.4) allows combining various elements into more elaborate visualizations:

    • Composing plots as programs/scripts
    • Preparing the canvass prior to plotting
    • Adding elements
    • Adjusting plotting parameters

Two important constraints for this chapter are:

  1. Visualizations often require transforming data into a specific format or shape. We ignore this here, but will return to this topic when wrangling data.

  2. We occasionally use colors, but do not cover how to specify and select colors in R. In the following, we occasionally use colors and color functions from the unikn package (see Appendix D: Using colors for details).


Anscombe, F. J. (1973). Graphs in statistical analysis. The American Statistician, 27(1), 17–21. https://doi.org/10.2307/2682899
Friendly, M. (2008). A brief history of data visualization. In Handbook of data visualization (pp. 15–56). Springer.
R Core Team. (2021). R base: A language and environment for statistical computing. R Foundation for Statistical Computing. https://www.R-project.org
Streeb, D., El-Assady, M., Keim, D., & Chen, M. (2019). Why visualize? Untangling a large network of arguments. IEEE Transactions on Visualization and Computer Graphics. https://doi.org/10.1109/TVCG.2019.2940026
Tufte, E. R. (2001). The visual display of quantitative information (2nd ed.). Graphics Press.
Unwin, A. (2008). Good graphics? In Handbook of data visualization (pp. 57–78). Springer.
Wilke, C. O. (2019). Fundamentals of data visualization: A primer on making informative and compelling figures. O’Reilly Media. https://clauswilke.com/dataviz/

  1. A deeper point made by this example is that assessments of similarity are always relative to some dimension or standard: The sets are similar or even identical with respect to their summary statistics, but different with respect to their x-y-coordinates. Whenever the dimension or standard of comparison is unknown, a statement of similarity is ill-defined.↩︎