Skip to content

Multiple graphs > boxplot

4 messages · David Gramaje, David Winsemius, Rui Barradas +1 more

#
On Oct 5, 2012, at 9:01 AM, David Gramaje wrote:

            
Two options:
A)
Melt the dataframe with reshape2::melt
then use boxplot( value ~ interaction(variable,treatment) )

B) 
Melt the dataframe
Use bwplot in lattice with a slightly more full featured formula interface

bwplot(value~cat|variable, data=amelt)

Option B is more beautiful in my opinion.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Rplot.pdf
Type: application/pdf
Size: 84789 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121005/85a6f90d/attachment.pdf>
-------------- next part --------------
#
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:
#
Does something like this make any sense?

library(reshape2)
library(ggplot2)
yy  <-  structure(list(A = c(23, 21, 21, 20, 19, 19), B = c(20, 18, 20, 
19, 20, 18), C = c(15, 15, 15, 12, 13, 13)), .Names = c("A", 
"B", "C"), class = "data.frame", row.names = c(NA, -6L))

y1  <-  melt(yy)  # using reshape2 

ggplot(y1, aes(variable, value))+ geom_boxplot() 

# or

ggplot(y1, aes(variable, value))+ geom_boxplot()  + facet_grid(variable ~ .)




John Kane
Kingston ON Canada
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!