Order of boxes in boxplot()
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