[R] bwplot scales in alphabetical order

Tim Clark mudiver1200 at yahoo.com
Wed Sep 30 09:21:47 CEST 2009


Dear List,

I know this has been covered before, but I don't seem to be able to get it right.  I am constructing a boxplot in lattice and can't get the scales in the correct alphebetical order.  I have already read that this is due to the way factors are treated, and I have to redefine the levels of the factors.  However, I have failed.  
As a simple example:

library(lattice)
id<-rep(letters[1:9], each=20)
x<-rep(seq(1:10),each=18)
y<-rnorm(180,50,20)

#Reverse alphebetical order
  bwplot(y~x|id, horizontal=FALSE)

#alphebetical order reading right to left
  id<-factor(id,levels = sort(id,decreasing = TRUE))
  bwplot(y~x|id, horizontal=FALSE)

It appears that bwplot plots scales from the bottom left to the top right. If so my factor levels would need to be levels=c(7,8,9,4,5,6,1,2,3). I tried that but can't seem to get the factor function to work.

#Did not work!
id<-factor(id,levels=c(7,8,9,4,5,6,1,2,3),lables=letters[1:9])

Your help would be greatly appreciated.

Tim





Tim Clark
Department of Zoology 
University of Hawaii




More information about the R-help mailing list