[R] how to reorder of groups and specify ylim for each row in lattice barchart

Peter Ehlers ehlers at ucalgary.ca
Fri Apr 23 01:54:23 CEST 2010

On 2010-04-21 21:13, zhenjiang xu wrote:
> R experts,
> Is there anyway to reorder inside each group? In the following example, the
> bar of year 1932 is always plotted before the bar of year 1931, may I change
> the order inside each groups of bars?

Do you mean a different order in different panels? That seems to
me to defeat the purpose of panels. I can't think of an easy way
to do that.

> library(lattice)
> barchart(yield ~ variety | site,data=barley, groups = year, layout =
> c(1,6),auto.key = list(points = FALSE, rectangles = TRUE, space =
> "right"),ylab = "Barley Yield (bushels/acre)",scales = list(x = list(rot =
> 45)))
> Another questions is: may I specify the various ranges of y axis for each
> row of the panels? In the example of above, how can I change the y range of
> "Waseca" panel to (40,70) from the default (0,80)? Please notice I don't
> want to set arguement "scales = list(y=list(relation='free'))", for the
> automatic various setting of ranges for different panels isn't good enough
> for me. Basically I'd like to manually control y ranges.

You can use scales() with
  y=list(relation='free', ylim=mylist)

where mylist is a list of ylims:
  mylim <- list(c(0,30), c(40,80), ....)

  -Peter Ehlers

> Thank you!

Peter Ehlers
University of Calgary

More information about the R-help mailing list