Skip to content

Instantly share code, notes, and snippets.

@aammd
Created November 1, 2015 20:45
Show Gist options
  • Save aammd/3d6873d378217ca8aa86 to your computer and use it in GitHub Desktop.
Save aammd/3d6873d378217ca8aa86 to your computer and use it in GitHub Desktop.
Anscombe's quartet
library(rvest)
quartet <- html("https://en.wikipedia.org/wiki/Anscombe's_quartet") %>%
html_table() %>%
.[[2]]
for (i in 1:length(names(quartet))) {
if (is.na(names(quartet)[i])) {
names(quartet)[i] <- names(quartet)[i - 1]
}
}
head(quartet)
four_strings <- unique(names(quartet))
long_form <- vector(mode = "list", length = 4)
names(long_form) <- four_strings
for (s in four_strings) {
long_form[[s]] <- quartet[,names(quartet) == s]
}
gathered <- lapply(long_form, function(x) {
df <- data.frame(x[-1,])
names(df) <- x[1,]
df
})
plyr::ldply(gathered) %>%
mutate(x = as.numeric(x),
y = as.numeric(y)) %>%
ggplot(aes(x = x, y= y)) + geom_point() + facet_wrap(~.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment