Hi Sorry for such an inane question - how do I control the order in which the boxes are plotted using boxplot() when I pass it a formula and a data.frame? It seems that the groups are plotted in alphabetical order... I want to change this.... Many thanks Mick
It is the order of the levels of the grouping factor. If `grp' is not a factor, it will be made into one (with levels in alphabetical order). On Thu, 7 Apr 2005, michael watson (IAH-C) wrote:> Sorry for such an inane question - how do I control the order in which > the boxes are plotted using boxplot() when I pass it a formula and a > data.frame? It seems that the groups are plotted in alphabetical > order... I want to change this....-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Thu, 7 Apr 2005, michael watson (IAH-C) wrote:> Sorry for such an inane question - how do I control the order in which > the boxes are plotted using boxplot() when I pass it a formula and a > data.frame? It seems that the groups are plotted in alphabetical > order... I want to change this....Mick, Here's the code I use to order boxes by decreasing median value. SubtDays is variable of interest ConChnl is original grouping factor. tMedians is a temp data frame dConChnl is new grouping factor with desired order boxplot(SubtDays ~ ConChnl, . ### Default ordering of boxes tMedians <- aggregate(SubtDays, list(ConChnl), median, na.rm = TRUE) dConChnl <- factor(ConChnl, levels = tMedians[order(tMedians$x), 1]) boxplot(SubtDays ~ dConChnl, . ### Ordered by decreasing median HTH, Jim Porzak Director of Analytics Loyalty Matrix, Inc. (415) 296-1141 x210 R.LoyaltyMatrix.com www.LoyaltyMatrix.com