[R] A rebel boxplot question

Rolf Turner r.turner at auckland.ac.nz
Thu Oct 4 22:03:32 CEST 2007


On 5/10/2007, at 3:39 AM, <p.valdes at arsystel.com> wrote:

> Dear R list members
> I am trying to improve a boxplot with 2 data sets. I run somethinkg  
> like
>
> boxplot(data1 ~ month, add=F, col = "red", ...)
> boxplot(data2 ~ month, add=T, col = "blue", ...)
>
> The problem is that the data from February are missing for data2, so R
> think that must take little more space between the data classes in  
> data 2
> and then both data gropus are not aligned. In the R documentation I  
> do not
> find any posile solution for tell R that I want reserve a extra  
> space for
> this month, So the boxplot is erroneous and the x axis have a strange
> numeration
>
> 1 2 3 4 54 65 76 ... etc
>
>  I would be grateful if anyone could suggest how to tell R That the
> boxplots must be fitted to the same x class in both data groups. To  
> make
> a false data group with a 0 valor for february is not aceptable in  
> this
> case

Your example is a bit confusing --- it must be ***month*** that  
February is missing from,
not data2!!! --- but basically if you make month into a ***factor***  
with levels equal to
the complete set of months, then boxplot() will leave a gap for any  
month that is missing.

E.g.

	clyde <- rnorm(100)
	melvin <- sample(letters[1:4],100,TRUE)
	melvin[melvin=="b"] <- "c"
	melvin <- factor(melvin,levels=letters[1:4])
	boxplot(clyde ~ melvin)

leaves a gap (an empty boxplot as it were) for b, and labels the x  
axis with "a", "b", "c", and "d".

BTW --- ``add'' and ``col'' do not seem to be arguments for boxplot().

			cheers,

				Rolf Turner


######################################################################
Attention:\ This e-mail message is privileged and confidenti...{{dropped}}



More information about the R-help mailing list