Instantly share code, notes, and snippets.

anonymous /AnscombeQuartet.r
Created Aug 15, 2014

Embed
What would you like to do?
data <- read.table("./AnscombeQuartet.csv", header = TRUE, sep =",", dec = ".", colClasses = c("numeric"))
mean(data$x1)
var(data$x1)
sapply(data, mean)
sapply(data, var)
par(mfrow=c(2,2), mar=c(2.0, 1.5, 1.5, 1.5), oma = c(2,2,2,2), pch = 16)
for(i in 1:4){
x = eval(parse(text = paste("data$x",i,sep="")))
y = eval(parse(text = paste("data$y",i,sep="")))
plot( x, y )
abline( lm(y ~ x) )
grid( 10,10 )
}
### Plot figures one by one:
# par(mfrow=c(2,2), mar=c(2.0, 1.5, 1.5, 1.5), oma = c(2,2,2,2), pch = 16)
# plot(data$x1, data$y1, xlab = "x", ylab = "y"); grid(10,10)
# abline(lm(data$y1~data$x1))
#
# plot(data$x2, data$y2, xlab = "x", ylab = "y"); grid(10,10)
# abline(lm(data$y2~data$x2))
#
# plot(data$x3, data$y3, xlab = "x", ylab = "y"); grid(10,10)
# abline(lm(data$y3~data$x3))
#
# plot(data$x4, data$y4, xlab = "x", ylab = "y"); grid(10,10)
# abline(lm(data$y4~data$x4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment