Skip to content

Instantly share code, notes, and snippets.

@even4void
Created August 5, 2011 23:26
Show Gist options
  • Save even4void/1128764 to your computer and use it in GitHub Desktop.
Save even4void/1128764 to your computer and use it in GitHub Desktop.
Tufte's boxplot
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))
@even4void
Copy link
Author

See Visualizing repeated measures (not longitudinal) for further customization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment