Introduction

“The graphical method has considerable superiority for the exposition of statistical facts over the tabular. A heavy bank of figures is grievously wearisome to the eye, and the popular mind is as incapable of drawing any useful lessons from it as of extracting sunbeams from cucumbers.” (Farquhar and Farquhar 1891)

Bright yellow sunbeams radiating from a center point. Poster for the 1977 film Gulliver's Travels.

A sliced cucumber.

Assessing models via visualizations

Anscombe’s (1973) quartet

use "https://tdmize.github.io/data/data/anscombe.dta", clear
tabstat Y* Xabc Xd, stat(mean sd min max) format(%4.2f) col(stats)
    Variable |      Mean        SD       Min       Max
-------------+----------------------------------------
          Yb |      7.50      2.03      3.10      9.26
          Yc |      7.50      2.03      5.39     12.74
          Yd |      7.50      2.03      5.25     12.50
          Ya |      7.50      2.03      4.26     10.84
        Xabc |      9.00      3.32      4.00     14.00
          Xd |      9.00      3.32      8.00     19.00
------------------------------------------------------
qui regress Ya Xabc
estimates store Ya
qui regress Yb Xabc
estimates store Yb
qui regress Yc Xabc
estimates store Yc
qui regress Yd Xd
estimates store Yd
esttab Ya Yb Yc Yd, b(2) se(2) title("Linear Regression Estimates")
Linear Regression Estimates
----------------------------------------------------------------------------
                      (1)             (2)             (3)             (4)   
                       Ya              Yb              Yc              Yd   
----------------------------------------------------------------------------
Xabc                 0.50**          0.50**          0.50**                 
                   (0.12)          (0.12)          (0.12)                   

Xd                                                                   0.50** 
                                                                   (0.12)   

_cons                3.00*           3.00*           3.00*           3.00*  
                   (1.12)          (1.13)          (1.12)          (1.12)   
----------------------------------------------------------------------------
N                      11              11              11              11   
----------------------------------------------------------------------------
Standard errors in parentheses
* p<0.05, ** p<0.01, *** p<0.001
library(foreign)            # load Stata datasets
library(ggplot2)            # main graphics package
library(modelsummary)       # coefficient plots & nice tables
library(cleanplots)         # Mize's graphics scheme

## Use cleanplots colors, markers, lines, and theme for all graphs ##
cleanplots_defaults()
theme_update(plot.title.position = "plot")   # titles start at left edge of graph

# Anscombe's quartet
anscombe <- read.dta("https://tdmize.github.io/data/data/anscombe.dta")

summary(anscombe[c("Ya", "Yb", "Yc", "Yd")])
       Ya               Yb              Yc              Yd        
 Min.   : 4.260   Min.   :3.100   Min.   : 5.39   Min.   : 5.250  
 1st Qu.: 6.315   1st Qu.:6.695   1st Qu.: 6.25   1st Qu.: 6.170  
 Median : 7.580   Median :8.140   Median : 7.11   Median : 7.040  
 Mean   : 7.501   Mean   :7.501   Mean   : 7.50   Mean   : 7.501  
 3rd Qu.: 8.570   3rd Qu.:8.950   3rd Qu.: 7.98   3rd Qu.: 8.190  
 Max.   :10.840   Max.   :9.260   Max.   :12.74   Max.   :12.500  
amod1 <- lm(Ya ~ Xabc, data = anscombe)
amod2 <- lm(Yb ~ Xabc, data = anscombe)
amod3 <- lm(Yc ~ Xabc, data = anscombe)
amod4 <- lm(Yd ~ Xd, data = anscombe)
modelsummary(list(amod1, amod2, amod3, amod4), stars = TRUE)
(1) (2) (3) (4)
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
(Intercept) 3.000* 3.001* 3.002* 3.002*
(1.125) (1.125) (1.124) (1.124)
Xabc 0.500** 0.500** 0.500**
(0.118) (0.118) (0.118)
Xd 0.500**
(0.118)
Num.Obs. 11 11 11 11
R2 0.667 0.666 0.666 0.667
R2 Adj. 0.629 0.629 0.629 0.630
AIC 39.7 39.7 39.7 39.7
BIC 40.9 40.9 40.9 40.9
Log.Lik. -16.841 -16.846 -16.838 -16.833
F 17.990 17.966 17.972 18.003
RMSE 1.12 1.12 1.12 1.12
sort Xabc // this forces lines to connect from left to right
// 0.a - Scatterplot of the data
twoway ///
    (scatter Ya Xabc) ///
    (scatter Yb Xabc) ///
    (scatter Yc Xabc) ///
    (scatter Yd Xd), ///
    ylab(0(5)15) xlab(0(5)20) ///
    title("[0.a] Anscombe's Quartet - All y & x Variables Have Same Mean and S
D")

[0.a] Scatterplot of Anscombe's four y variables against x, each set in its own color and marker: the sets follow different patterns even though their summary statistics are the same.

# 0.a - Scatterplot of the data
ggplot(anscombe) +
  geom_point(aes(x = Xabc, y = Ya), color = cleanplots_colors("red"), size = 3) +
  geom_point(aes(x = Xabc, y = Yb), color = cleanplots_colors("ltblue"), size = 3) +
  geom_point(aes(x = Xabc, y = Yc), color = cleanplots_colors("gray"), size = 3) +
  geom_point(aes(x = Xd,   y = Yd), color = cleanplots_colors("black"), size = 3) +
  labs(x = "X", y = "Y",
       title = "[0.a] Anscombe's quartet - All y & x variables have same mean and SD")

[0.a] Scatterplot of Anscombe's four y variables against x, each set in its own color: the sets follow different patterns even though their summary statistics are the same.

// 0.b - Add connected lines
twoway ///
    (connected Ya Xabc) ///
    (connected Yb Xabc) ///
    (connected Yc Xabc) ///
    (scatter Yd Xd), ///
    ylab(0(5)15) xlab(0(5)20) ///
    title("[0.b] Anscombe's Quartet - All y & x Variables Have Same Mean and S
D")

[0.b] The same scatterplot with lines connecting the points of the first three sets: one set rises roughly linearly with noise, one is a smooth upside-down U, and one is a straight line with a single outlier; the fourth set has all but one point at the same x value.

# 0.b - Add connected lines
ggplot(anscombe) +
  geom_point(aes(x = Xabc, y = Ya), color = cleanplots_colors("red"), size = 3) +
  geom_line( aes(x = Xabc, y = Ya), color = cleanplots_colors("red")) +
  geom_point(aes(x = Xabc, y = Yb), color = cleanplots_colors("ltblue"), size = 3) +
  geom_line( aes(x = Xabc, y = Yb), color = cleanplots_colors("ltblue")) +
  geom_point(aes(x = Xabc, y = Yc), color = cleanplots_colors("gray"), size = 3) +
  geom_line( aes(x = Xabc, y = Yc), color = cleanplots_colors("gray")) +
  geom_point(aes(x = Xd,   y = Yd), color = cleanplots_colors("black"), size = 3) +
  labs(x = "X", y = "Y",
       title = "[0.b] Anscombe's quartet - All y & x variables have same mean and SD")

[0.b] The same scatterplot with lines connecting the points of the first three sets: one set rises roughly linearly with noise, one is a smooth upside-down U, and one is a straight line with a single outlier; the fourth set has all but one point at the same x value.

The Methodology Center illustration: small line drawings of graphs around a central MCAP circle.

The Anscombe line plot that one of the Methodology Center illustration's small drawings is based on.

*Read about The Methodology Center graphic

Good data visualization balances art and science

“Data visualization is part art and part science. The challenge is to get the art right without getting the science wrong, and vice versa.” (Wilke 2019 p.1)

  • Too many data visualization guides lean on aesthetic opinions only
    • Aesthetics are important…
  • But there is a large scientific literature on what makes an effective data visualization
  • Goal is to learn general principles to guide any data or model visualization
    • To make visualizations that are both effective and beautiful
  • Along the way, add to your toolbox of visualization strategies
    • Learn what tools are effective for what types of data and situations

The Wes Anderson film color palette: rows of colored bars for The Royal Tenenbaums, Rushmore, The Life Aquatic, and Fantastic Mr. Fox.

Poster for Fantastic Mr. Fox.

Back to top