s-news
[Top] [All Lists]

Re: Ordering of factors in barchart

To: Gerald.Jean@spgdag.ca
Subject: Re: Ordering of factors in barchart
From: Douglas Bates <bates@stat.wisc.edu>
Date: 25 Sep 2003 12:31:49 -0500
Cc: s-news@wubios.wustl.edu
In-reply-to: <OF487A01D1.EC01C867-ON85256DAC.0054B9B2@spgdag.ca>
References: <OF487A01D1.EC01C867-ON85256DAC.0054B9B2@spgdag.ca>
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp)
Gerald.Jean@spgdag.ca writes:

> Hello S-users,
> 
> I am trying to use barchart to plot the data from a small data.frame.  No
> matter how the rows of the input data.frame are ordered barchart plots them
> always in the same order; I would like to have them in the order they are
> inputted.  Following is my small data.frame and the code I am using.
> 
> > ttt.bar.df
>         v     n
>  1  00-04 15372
>  2  05-09 12827
>  3  10-14 19062
>  4  15-19 16029
>  5  20-24 16925
>  6  25-29 21616
>  7  30-39 25117
>  8  40-49 19986
>  9  50-74 15860
> 10  75-99  4289
> 11  100 +  4240
> 
> ttt.pen <- barchart(v ~ n, data = ttt.bar.df,
>                     aspect = 'fill', xlab = "Unit\351s",
>                     main = paste(
>                       " Distribution des unit\351s pour ", ttt.var,
>                       sep = ''))
> print(ttt.pen)
> 
> barchart seems to plot the bars in alphabetical order of the variable "v"
> and hence the "100 +" comes in between "15-19" and "20-24"; not what I
> want, I want them plotted just the way they are!
> 
> Thanks,
> 
> Gérald Jean
> Analyste-conseil (statistiques), Actuariat
> télephone            : (418) 835-4900 poste (7639)
> télecopieur          : (418) 835-6657
> courrier électronique: gerald.jean@spgdag.ca

Change the v column to an ordered factor with the levels ordered as
you want them to be.

<Prev in Thread] Current Thread [Next in Thread>