On Thu, Jan 28, 2010 at 8:59 PM, Santosh <santosh2005 at gmail.com>
wrote:> Dear Rxperts..
>
> what settings in barplot and histogram do I use, to show bars in an
> monotonously increasing or decreasing order of the frequency of a
> categorical variable?
See ?reorder. Typical usage would be (in lattice)
barchart(y ~ reorder(f, y))
In your example,
barchart(a2 ~ reorder(names(a2), a2), origin = 0)
barchart(sort(a2)) would also work (unlike barplot, all labels will be shown).
-Deepayan
> an example is provided below..
>
> histogram(~factor(sample(letters,200,rep=T)))
>
> I was able to get it in 3 - 4 steps.. l
> a1 <- sample(letter,200,rep=T)
> a2 <- table(a1)
> barplot(a2); barplot(sort(a2)) # all variables are not displayed on the
> x-axis in the barplot
> histogram(factor(a1)) # the resulting bars are not shown in seqentially
> increasing or decreasing order
>
> how do I use similar plots if I have data.frame...
> example is shown below..
>
> b1 <- data.frame(lets=sample(letters,200,rep=T),n=seq(200))
> barplot(sort(table(b1$lets))
> histogram(b1$lets)
>
> Regards,
> Santosh