Skip to content

Instantly share code, notes, and snippets.

@jalapic
Last active Aug 29, 2015
Embed
What would you like to do?
#### Anscombe's Quartet
temp <-
data.frame( x1 = c(10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5),
y1 = c(8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68),
x2 = c(10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5),
y2 = c(9.14, 8.14, 8.74, 8.77, 9.26, 8.1, 6.13, 3.1, 9.13, 7.26, 4.74),
x3 = c(10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5),
y3 = c(7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73),
x4 = c(8, 8, 8, 8, 8, 8, 8, 19, 8, 8, 8),
y4 = c(6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.5, 5.56, 7.91, 6.89)
)
# All have correlation of 0.816
cor(temp$x1, temp$y1)
cor(temp$x2, temp$y2)
cor(temp$x3, temp$y3)
cor(temp$x4, temp$y4)
# All x have mean of 9
mean(temp$x1)
mean(temp$x2)
mean(temp$x3)
mean(temp$x4)
# All y have mean of 7.5
mean(temp$y1)
mean(temp$y2)
mean(temp$y3)
mean(temp$y4)
# All x have variance of 11
var(temp$x1)
var(temp$x2)
var(temp$x3)
var(temp$x4)
# All y have variance of 4.1
var(temp$y1)
var(temp$y2)
var(temp$y3)
var(temp$y4)
# longform dataframe
temp1<-
data.frame(x = c(temp$x1, temp$x2, temp$x3, temp$x4),
y = c(temp$y1, temp$y2, temp$y3, temp$y4),
id = rep(c(1:4), each = 11))
# plot
library(ggplot2)
ggplot(temp1, aes(x,y)) +
geom_point(size=5, pch=16) +
theme_bw() +
facet_wrap( ~ id, ncol = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment