Created
August 5, 2011 23:26
-
-
Save even4void/1128764 to your computer and use it in GitHub Desktop.
Tufte's boxplot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tufte.boxplot <- function(x, g) { | |
k <- nlevels(g) | |
crit.val <- tapply(x, g, median) | |
plot(1:k, crit.val, ylim=c(min(x)*1.1, max(x)*1.1), pch=19, | |
xlab=deparse(substitute(g)), ylab=deparse(substitute(x))) | |
for (i in 1:k) { | |
tmp <- boxplot.stats(x[as.numeric(g)==i]) | |
segments(i, tmp$stats[1], i, tmp$stats[2]) | |
segments(i, tmp$stats[4], i, tmp$stats[5]) | |
points(rep(i, length(tmp$out)), tmp$out, cex=.8) | |
} | |
} | |
dd <- data.frame(x=rnorm(50*100), g=gl(50,100)) | |
with(dd, tufte.boxplot(x, g)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credits: W. Huber on CrossValidated.