On Tue, Jul 7, 2009 at 3:03 PM, <peter_kap...@fws.gov> wrote: > Hi, > > I have been trying to re-order several items in a trellised barchart > display in lattice, but can't seem to figure it out. > > ###sample code, Stage and Colony have 2 and 3 levels respectively. > > barchart(Activity ~ Percent | Stage + Colony, data = Percent.df, > horizontal = TRUE, layout = c(2,3), > xlab = "Percent Time Engaged in Activity", > ylab = "Activity") > > This essentially produces the display I would like, only I would like to > have the second column first and the first and third panels switched. In > addition, I would like to re-order the y-axis labels ("Activities") so > that they are in alphabetical order starting with A at the top...currently > A is at the bottom. I have been able to switch the actual data in the > panels useing barchart(rev(Activity~ Percent...but cannot get the actual > labels to switch. Thanks in advance.
You need to read up on levels() of factors; in both cases, the ordering is determined by the levels, which are by default ordered lexically for character vectors, but can be specified manually, e.g. factor(Activity, levels = rev(sort(unique(Activity))) For the first question, there is a shortcut to reorder levels of conditioning variables: p <- barchart(Activity ~ Percent | Stage + Colony, data = Percent.df, ...) p[, c(2, 3, 1)] -Deepayan ______________________________________________ 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.