[R] reorder() in the latticeExtra library

David Winsemius dwinsemius at comcast.net
Sat Nov 3 08:47:17 CET 2012


On Nov 2, 2012, at 8:04 PM, JDINIS wrote:

> Hello all, thanks for your time and help. Below are my commands, and it
> generates a really nice plot, however I am not happy with the reorder()
> function. I would like the order to be the same as they appear in the
> genotype variable  "genotype <- c("CJ1450 NW 4/25/12","CJ1450 BAL
> 4/25/12","CJ1450 NW 4/27/12","CJ1450 BAL 4/27/12","CJ1721 NW
> 4/27/12","CJ1721 BAL 4/27/12","CJ1721 NW 4/29/12","CJ1721 BAL 4/29/12" )"
> and not as it is currently coded.
> 
> Is there any way to turn off the reorder, or set it up so the values appear
> in the order above, thank you again!
> 
> (I am open to all suggestions)
> 
> JD
> 
> 
> genotype <- c("CJ1450 NW 4/25/12","CJ1450 BAL 4/25/12","CJ1450 NW
> 4/27/12","CJ1450 BAL 4/27/12","CJ1721 NW 4/27/12","CJ1721 BAL
> 4/27/12","CJ1721 NW 4/29/12","CJ1721 BAL 4/29/12" )
> #paste("Animal", as.roman(1:8), sep = "-") 
> plant.height <- c(0.001173003, 0.001506127, 0.001361596, 0.001922572,
> 0.034272147, 0.030466017, 0.001654299, 0.001071724)
> SE <- c(0.000444123, 0.000290096, 0.000372844, 0.00197687, 0.033945128,
> 0.035231568, 0.001094518, 0.000423545) 
> lower <- plant.height - SE; upper <- plant.height + SE 
> x <- data.frame(group = genotype, lower = lower, est = plant.height, upper =
> upper)
> 
> library(latticeExtra) 
> segplot(reorder(genotype, est) ~ lower + upper, data = x, draw.bands =
> FALSE, centers = est, segments.fun = panel.arrows, ends = "both", angle =
> 90, length = 0, par.settings = simpleTheme(pch = 19, col = 1), xlab =
> expression("nucleotide diversity " %+-% " sd"), panel = function(x, y, z,
> ...) { 
> panel.abline(h = z, col = "grey", lty = "dashed") 
> panel.abline(v = 14.20, col = "grey") 
> panel.segplot(x, y, z, ...)}) 

Wouldn't you just define genotype as a factor with the desired sequence of levels and remove the call to reorder?

-- 
David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list