Skip to content
Back to formatted view

Raw Message

Message-ID: <AAA59475-81B2-4C10-9CB8-A0F31AA398DD@comcast.net>
Date: 2009-03-04T20:00:38Z
From: David Winsemius
Subject: Grouped Boxplot
In-Reply-To: <1F9EFAA7-03B4-4FBB-946D-61E1F51FA479@eawag.ch>

Q1:
See if this seems any better. I took the liberty of reconstruction  
your initial example in a longer dataframe:

dta <- data.frame(val = sample(t,1000), g = gl(4, 250, labels=c("A",  
"B", "C", "D")) , G2 = gl(2,1, labels=c("XX", "YY")))

#arguments to data.frame are recycled so one does not need to make the  
gl call with a
# length of 500, in fact , that only confuses things (or at least it  
does for me).

table(dta$G2,dta$g)

#       A   B   C   D
#  XX 125 125 125 125
#  YY 125 125 125 125

  boxplot( val ~ G2 + g, data=dta)

Q2:

?boxplot  #especially parameter at=

boxplot( val ~ g + G2, data=dta, at = 0.8*c(1,2,3,4,6,7,8,9),  
boxwex=0.4)

-- 
David Winsemius

On Mar 4, 2009, at 1:50 PM, soeren.vogel at eawag.ch wrote:

> Pls forgive me heavy-handed data generation -- newby ;-)
>
> ### start ###
> # example data
> g <- rep.int(c("A", "B", "C", "D"), 125)
> t <- rnorm(5000)
> a <- sample(t, 500, replace=TRUE)
> b <- sample(t, 500, replace=TRUE)
>
> # what I actually want to have:
> boxplot(a | b ~ g)
>
> # but that does obviously not produce what I want, instead
> i <- data.frame(g, a, rep("one", length(g)))
> j <- data.frame(g, b, rep("two", length(g)))
> names(i) <- c("Group", "Number", "Word")
> names(j) <- c("Group", "Number", "Word")
> k <- as.data.frame(rbind(i, j))
> boxplot(k$Number ~ k$Word * k$Group)
> ### end ###
>
> Questions: (1) Is there an easier way? (2) How can I get additional  
> space between the A:D groups?
>
> Thank you
>
> S?ren
>
> ______________________________________________
> 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.