Hello Thank you for the advice on vector. I found a previous mail on this issue and pasted it below.
Now here comes a different scenario. I have more than 20 boxplots and just wanted the first two from the left to be red and the rest to be blue. Please kindly advise how to code the color without writing the color names 18 times. Thanks again. Elaine code for color using vector dataset <- data.frame ( time = rep(1:5,times=9), genotype = factor(rep(rep (c("A","B","C"),each=5),times=3 )), location= factor(rep (paste("LOC",1:3),each=15)), color = rep (rep (c("red","green","blue"),each=5),times=3 ), result = rnorm (45)) library(lattice) # The black, red, green behaviour you were seeing is because # dataset$color is a factor dataset$color # which is coded 1, 2, 3 levels = ("red", "green", "blue"). # This is being interpreted as the first three colours of the palette pallete() # coerce the vector to a character vector as.character(dataset$color) # gives you xyplot( result ~ time | location, data=dataset,groups=genotype, fill.color = as.character(dataset$color), panel = function(x, y,fill.color,...,subscripts) { fill = fill.color [subscripts] panel.xyplot(x, y,pch=19, col=fill, type ="b")} ) # Lines only take a single value so only the first value of the vector, # "red", is passed to line colour. # these are simple alternatives xyplot( result ~ time | location, data=dataset, groups=genotype, pch=c(1,2,3), type="b", col=c("red","blue","green")) xyplot( result ~ time | location, data=dataset, groups=genotype, pch=c(1,2,3), type="b", col=dataset$color) # or use par.settings <- list(superpose.symbol = list(col = c("red", "green", "blue"), fill = c("red", "green", "blue")), superpose.line = list(col = c("red", "green", "blue")) ) xyplot( result ~ time | location, data=dataset,groups=genotype,pch=19, type = "b", par.settings = par.settings) On Sun, Feb 24, 2013 at 6:29 PM, Andrés Aragón Martínez <armand...@gmail.com > wrote: > Hi Elaine, > > In your dataset create a vector with the order in which you want appear > the levels, then use that vector in the argument "reorder". > > Andrés AM > > > > > > El 24/02/2013, a las 00:59, Elaine Kuo <elaine.kuo...@gmail.com> escribió: > > > Hello, > > > > I tried to manipulate the order of boxplots using the "reorder" below and > > worked. > > > > However, please kindly advise how to specify the colors of each boxplot > > (bird group), > > like red, green, and blue, from the left to the right. > > Thanks again. > > > > code > > bwplot(GE_distance~OF, data=dataN, > > index.cond = function(x, y) mean(y), > > xlab=list("Taxonomy group", cex = 1.6), > > prepanel = function(x, y) { > > list(xlim = levels(reorder(x, y))) > > }, > > panel = function(x, y, ...) { > > panel.bwplot(reorder(x, y),y, ...) > > }) > > > > data > > > > migration distance (km) bird group > > > > 10987 Charadriiformes > > > > 9867 Charadriiformes > > > > 8702 Charadriiformes > > > > 9432 Charadriiformes > > > > 9054 Charadriiformes > > > > 5087 Falconiiformes > > > > 5783 Falconiiformes > > > > 5298 Falconiiformes > > > > 5687 Falconiiformes > > > > 3987 Gruiformes > > > > 3298 Gruiformes > > > > 3567 Gruiformes > > > > 3409 Gruiformes > > > > 3321 Gruiformes > > > > 3598 Gruiformes > > > > > > > > On Sat, Feb 23, 2013 at 6:29 AM, Ben Bolker <bbol...@gmail.com> wrote: > > > >> Elaine Kuo <elaine.kuo.tw <at> gmail.com> writes: > >> > >>> > >>> Hello > >>> > >>> I am using lattice bwplot to draw migration distance of three groups of > >>> birds. > >>> > >>> The boxplots from the left to right is displayed > >>> in alphabetic order of the boxplot names, as the default setting. > >>> > >>> However, I would like the boxplots from the left to right to be > displayed > >>> according to the migration distance from the short values to the long > >> ones. > >>> > >>> In the data below, from the left to the right should be Gruiformes, > >>> Falconiiformes, and Charadriiformes. > >>> > >>> Please kindly advise how to modify the code below. > >>> > >> > >> Define the order of the levels of your factor > >> accordingly. Take a look at > >> > >> http://stackoverflow.com/questions/15033107/ > >> specifing-order-of-lattice-plot-panels > >> > >> (broken URL to meet gmane line length limits) > >> > >> ______________________________________________ > >> R-help@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. > >> > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@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. > > [[alternative HTML version deleted]]
______________________________________________ R-help@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.