AE 00: Visualizing the Datasaurus Dozen using the grammar of graphics and {ggplot2}

Application exercise
Modified

August 17, 2026

Important

Go to ae-00-datasaurus and clone the repo in Positron to get started.

This AE is ungraded.

Warning

ae-00-datasaurus is hosted on GitHub.com because we have not configured your authentication method for Cornell’s GitHub. We will do this tomorrow in discussion sections.

Packages

In this application exercise we will work with two packages:

  • {datasauRus} which contains the dataset, and
  • {tidyverse} which is a collection of packages for doing data analysis in a “tidy” way.

Load these packages by running the code cell below. You can do this by clicking on the Run cell (triangle) at the top of the cell, or by placing your cursor in the cell and pressing Ctrl + Shift + Enter (Cmd + Shift + Enter on a Mac).

Note

The rendered document will include a message about which packages the {tidyverse} package is loading along with it. It’s just R being informative, a message does not indicate anything is wrong (it’s not a warning or an error).

Data

The data frame we will be working with today is called datasaurus_dozen and it’s in the {datasauRus} package. Actually, this single data frame contains 13 datasets, designed to show us why data visualization is important and how summary statistics alone can be misleading. The different datasets are marked by the dataset variable.

Note

If it’s confusing that the data frame is called datasaurus_dozen when it contains 13 datasets, you’re not alone! Have you heard of a baker’s dozen?

To find out more about the dataset, type the following in your console.

?datasaurus_dozen

A question mark before the name of an object will always bring up its help file. This command must be run in the console. Alternatively, you can use the help() function.

help(datasaurus_dozen)

Exercises

Exercise 1

Based on the help file, how many rows and how many columns does the datasaurus_dozen file have? What are the variables included in the data frame?

Add response here.

Let’s take a look at what these datasets are. To do so we can check the distinct() values of the dataset variable:

datasaurus_dozen |>
  distinct(dataset)
# A tibble: 13 × 1
   dataset   
   <chr>     
 1 dino      
 2 away      
 3 h_lines   
 4 v_lines   
 5 x_shape   
 6 star      
 7 high_lines
 8 dots      
 9 circle    
10 bullseye  
11 slant_up  
12 slant_down
13 wide_lines

The original Datasaurus (dino) was created by Alberto Cairo in this great blog post. The other Dozen were generated using simulated annealing and the process is described in the paper Same Stats, Different Graphs: Generating Datasets with Varied Appearance and Identical Statistics through Simulated Annealing by Justin Matejka and George Fitzmaurice.1 In the paper, the authors simulate a variety of datasets that have the same summary statistics as the Datasaurus but very different distributions.

Exercise 2

Plot x vs. y for the dino dataset. Then, calculate the correlation coefficient between x and y for this dataset.

# add code here

Exercise 3

Plot x vs. y for the circle dataset. You can (and should) reuse code we introduced above, just replace the dataset name with the desired dataset. Then, calculate the correlation coefficient between x and y for this dataset. How does this value compare to the r of dino?

# add code here

Add response here.

Exercise 4

Plot x vs. y for the star dataset. You can (and should) reuse code we introduced above, just replace the dataset name with the desired dataset. Then, calculate the correlation coefficient between x and y for this dataset. How does this value compare to the r of dino?

# add code here

Add response here.

Exercise 5

Finally, plot all datasets at once. In order to do this we will make use of faceting, given by the code below:

# add code here

And we can use the group_by() function to generate all the summary correlation coefficients. We’ll go through these functions in a couple of weeks when we learn about data wrangling.

datasaurus_dozen |>
  group_by(dataset) |>
  summarize(r = cor(x, y))
# A tibble: 13 × 2
   dataset          r
   <chr>        <dbl>
 1 away       -0.0641
 2 bullseye   -0.0686
 3 circle     -0.0683
 4 dino       -0.0645
 5 dots       -0.0603
 6 h_lines    -0.0617
 7 high_lines -0.0685
 8 slant_down -0.0690
 9 slant_up   -0.0686
10 star       -0.0630
11 v_lines    -0.0694
12 wide_lines -0.0666
13 x_shape    -0.0656

Briefly comment on what you notice about the plots and the correlations between x and y values within each of them (one or two sentences is fine!).

Add response here.

Acknowledgments

Footnotes

  1. Matejka, Justin, and George Fitzmaurice. “Same stats, different graphs: Generating datasets with varied appearance and identical statistics through simulated annealing.” Proceedings of the 2017 CHI Conference on Human Factors in Computing Systems. ACM, 2017.↩︎