The R package datasauRus was created by Alberto Cairo. The package has 13 paired data sets with almost exactly the same means, standard deviations, and correlations. It demonstrates why summary statistics aren’t enough and that one should always graph data. If you are interested in how the data set was constructed, you can read Same Stats, Different Graphs.
In the animation, I added a data set between each of the 13 partly because I thought it made the animation look neat and partly so you can see that the summary statistics in the animation do change.
If you enjoy this animation or found the R code below useful, then please consider sharing the, subscribing to Briefed by Data (you can do it for free), and commenting.
R Code
## Animation created by Thomas J Pfaff for Briefed by Data https://briefedbydata.substack.com/
## Packages
library(dplyr)
library(ggplot2)
library(gganimate)
library(datasauRus)
## Colors
MyPurple <- "#5B005B"
MyLightP <- "#dfdbdf"
MyLightP2 <- "#f8f4f8"
MyLightP3 <- "#fcfafc"
## Organize data
data <- datasaurus_dozen
data$group <- rep(2 * (1:13), each = 142)
data1 <- data.frame(dataset = rep(c("G1","G2","G3","G4","G5","G6","G7","G8","G9","G10","G11","G12","G13"),each=142),
x = rnorm(142 * 13, 15, 2),
y = rnorm(142 * 13, 15, 2),
group=rep(2 * (1:13)-1, each = 142)
)
data2 <- rbind(data,data1)
data2 <- data2 %>% group_by(dataset) %>%
mutate(MeanX = format( round( mean(x), 2), nsmall = 2),
MeanY = format( round( mean(y), 2), nsmall = 2),
SdX = format( round( sd(x), 2), nsmall = 2),
SdY = format( round( sd(y), 2), nsmall =2 ),
N = n(),
r= format( round( cor(x,y), 2), nsmall=2)) %>% ungroup()
CaptionData <- "Data: R Datasaurus"
## Create Animation
A1 <- ggplot(data2, aes( x = x, y = y,
label = paste("Mean ( X,Y ) = ( ", MeanX, ", ", MeanY, " )\nSd ( X,Y ) = ( ",
SdX , ", ", SdY, " )\nr = ", r, sep="" ))) +
geom_point( color = MyPurple, size = 5) +
xlim( 0, 110 ) + ylim( 0, 110 ) +
transition_states(group, transition_length = 3, state_length = 2 ) +
ease_aes('quadratic-in-out') +
geom_text( aes(0, 97), size = 6, hjust = 0, vjust=0, color = MyPurple) +
theme(axis.text = element_text( size = 14 ),
plot.title = element_text( size = 20 ),
plot.background = element_rect( fill = MyLightP3 ),
panel.background = element_rect( fill = MyLightP ),
legend.background = element_rect( fill = MyLightP2 ),
plot.caption = element_text( hjust = c(1, 0), size = c(14, 14),
color = c(MyPurple, "black"))) +
labs(title="13 Data Sets Same Stats Different Graphs",
y = NULL, x= NULL,
caption = c("Briefed by Data || Thomas J Pfaff",CaptionData))
DatasauRusAnimate <- animate(A1, fps = 10, duration = 20, width = 936, height = 936)
anim_save("DatasauRusAnimate2.gif", DatasauRusAnimate)