[R] Sorting groups in bwplot chart

David Winsemius dwinsemius at comcast.net
Fri Aug 27 15:20:01 CEST 2010

On Aug 27, 2010, at 9:03 AM, Jan Hornych wrote:

> Hi all,
> I am just curious how to sort the groups in a categorical box plot  
> chart
> bwplot
> here is the example:
> d<-data.frame(sample(rep(month.abb,20), 100), runif(100,1,10));
> colnames(d) <- c("Month", "Value");
> bwplot(d$Month ~ d$Value);
> as you can see Months are not sorted alphabetically.

But, they are sorted alphabetically on my device.

I would have expected a request to get them sorted in calendar order,  
which can be accomplished by changing your dataframe construction to  
explicitly use a factor call (rather than the implicit one)  allowing  
you to add a levels specification:

d <- data.frame(
          mon=factor( sample(rep(month.abb,20), 100), levels=month.abb),

And note that your superfluous ";"'s will mark you as a recovering SAS  

> Does anybody know ho to
> sort those on the chart level?
> Thank you
> Jan

David Winsemius, MD
West Hartford, CT

 > sessionInfo()
R version 2.11.1 Patched (2010-06-14 r52281)

[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] tcltk     splines   stats     graphics  grDevices utils      
datasets  methods   base

other attached packages:
  [1] np_0.40-3             cubature_1.0           
boot_1.2-42           eha_1.2-18
  [5] sqldf_0.3-5           chron_2.3-35           
RSQLite.extfuns_0.0.1 RSQLite_0.9-2
  [9] DBI_0.2-5             gsubfn_0.5-3           
proto_0.3-8           WriteXLS_1.9.0
[13] rms_3.0-0             Hmisc_3.8-1           survival_2.35-8        
[17] lattice_0.18-8

loaded via a namespace (and not attached):
[1] cluster_1.12.3 grid_2.11.1    tools_2.11.1

More information about the R-help mailing list