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

Peter Ehlers ehlers at ucalgary.ca
Fri Apr 23 17:51:51 CEST 2010


Works for me. Did you replace the '....' in mylist()
with appropriate c(,) code? For example:

mylist <- list(c(0,30), c(40,80), c(0,50),
                c(0,50), c(0,50), c(0,50))

  -Peter Ehlers

On 2010-04-23 9:22, zhenjiang xu wrote:
> Peter, thanks, but that doesn't work. Did I missed something?
>
> library(lattice)
> mylist<- list(c(0,30), c(40,80), ....)
> 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), y=list(relation='free', ylim=mylist)))
>
> On Thu, Apr 22, 2010 at 7:54 PM, Peter Ehlers<ehlers at ucalgary.ca>  wrote:
>
>> 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, thanks, but that doesn't work. Did I missed something?
>
> library(lattice)
> mylist<- list(c(0,30), c(40,80), ....)
> 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), y=list(relation='free', ylim=mylist)))
>
>
>>
>>   -Peter Ehlers
>>
>>
>>> Thank you!
>>>
>>
>> --
>> Peter Ehlers
>> University of Calgary
>>
>
>
>

-- 
Peter Ehlers
University of Calgary



More information about the R-help mailing list