Created
July 5, 2012 05:58
-
-
Save astatham/3051652 to your computer and use it in GitHub Desktop.
lboxplot function - boxplots lists of lists
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
lboxplot <- function(x, cols=2:(length(x)+1), ...) { | |
xl <- length(x) | |
if (xl<2) stop("Length of x must be >=2") | |
xn <- sapply(x, length) | |
if (!all(xn==xn[1])) stop ("Element lengths of x must all be the same") | |
xnames <- sapply(x, names) | |
if (!all(apply(xnames, 1, function(y) all(y==y[1])))) stop("Each element of x must have matching names") | |
xn <- xn[1] | |
xu <- unlist(x, recursive=FALSE)[rep(1:xn, each=xl)+rep((1:xl-1)*xn, xn)] | |
boxplot(xu, col=cols, xaxt="n", ...) | |
axis(1, seq(1+(xl-1)/2, length(xu)-(xl-1)/2, length.out=xn), names(x[[1]]), las=2) | |
abline(v=1:(xn-1)*xl+0.5, lty=2, col="red") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment