[R] Multiple graphs > boxplot

Rui Barradas ruipbarradas at sapo.pt
Fri Oct 5 18:57:35 CEST 2012


Hello,

I've once written a function that does more or less what you want, but 
it has no formula interface.

# Input:
#    x - matrix or data.frame of numeric vectors to graph
#    by - a factor or coercible to factor
multi.boxplot <- function(x, by, col=0, ...){
     x <- as.data.frame(x)
     uniq.by <- unique(by)
     by <- factor(by)
     len <- length(uniq.by) - 1
     n <- ncol(x)
     n1 <- n + 1
     col <- rep(col, n)[seq_len(n)]
     boxplot(x[[ 1 ]] ~ by, at = 0:len*n1 + 1,
         xlim = c(0, (len + 1)*n1), ylim = range(unlist(x)), xaxt = "n", 
col=col[1], ...)
     for(i in seq_len(n)[-1])
         boxplot(x[[i]] ~ by, at = 0:len*n1 + i, xaxt = "n", add = TRUE, 
col=col[i], ...)
     axis(1, at = 0:len*n1 + n1/2, labels = uniq.by, tick = TRUE)
}


a <- matrix(data=runif(300,max=2), nrow=100, ncol=3)
fac <- sample(letters[1:4], 100, TRUE)

multi.boxplot(a, fac)


Hope this helps,

Rui Barradas
Em 05-10-2012 17:01, David Gramaje escreveu:
>
> Dear all
>
> I am trying to represent a dependent variable (treatment) against different independent variables (v1, v2, v3....v20). I am using the following command:
>
> boxplot(v1~treatment,data=y, main="xxxxxx",xlab="xxxxxx", ylab="xxxxxx")
>
> However, it provides me only one graph for v1~treatment. For the other comparisons, I have to repeat the same command but changing the parameters. My intentions is to get different plots in just one sheet using only one command. Is it possible to join the same order for all the comparisons in only one command?
>
> Thanks
> David
>   		 	   		
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list