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.
|