Skip to content

Instantly share code, notes, and snippets.

@steveharoz
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveharoz/9599308 to your computer and use it in GitHub Desktop.
Save steveharoz/9599308 to your computer and use it in GitHub Desktop.
Melted Anscombe's Quartet
library(reshape2)
library(plyr)
library(ggplot2)
library(grid)
anscombe2 = melt(anscombe, measure.vars=c('x1', 'x2', 'x3', 'x4'), variable.name='number', value.name='x')
anscombe2$number = substring(anscombe2$number, 2)
anscombe2 = adply(anscombe2, 1, function(r){
r['y'] = r[paste0('y', r['number'])]
return(r)
})
anscombe2 = anscombe2[,c('number', 'x', 'y')]
anscombe2$number = paste('Set', anscombe2$number)
library('Cairo')
CairoWin()
ggplot(anscombe2, aes(x=x, y=y)) +
geom_point(size=4, color='orange', alpha = 0.7) +
geom_smooth(method="lm", fill=NA, fullrange=TRUE, size=1) +
scale_x_continuous(limits=c(0,20), expand=c(0,0)) +
scale_y_continuous(limits=c(0,15), expand=c(0,0)) +
facet_wrap(~ number, scales="free") + #theme_minimal() +
theme(
text = element_text(size = 15),
panel.background = element_blank(),#element_rect(colour = 'white'),
#axis.title = element_text(face = "italic"), # 12 pt
#axis.text = element_text(), # 12 pt
axis.line = element_line(colour="black"),
axis.ticks = element_blank(),
panel.grid.major = element_line(colour = "#CCCCCC"),
panel.grid.minor = element_blank(),
panel.margin = unit(50, "points")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment