[R] locating boxplot in bwplot (lattice)

Andrés Aragón Martínez armandres at gmail.com
Sun Feb 24 11:29:13 CET 2013


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.tw at 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 <bbolker at 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 at 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 at 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.



More information about the R-help mailing list