[R] Histogram

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Nov 18 16:58:37 CET 2003


"Arend P. van der Veen" <apv at capital.net> writes:

> Hi,
> 
> I have what should be a simple question.  I would like to generate a
> histogram of
> 
> x <- c("a","b","c","b","c","c")
> 
> where the first bar to be labeled 'c' with height 3, second bar to be
> labeled 'b' with height 2 and third bar to be labeled 'a' with height 1.
> 
> This should be an easy task in R but I think I am missing something?

That's not a histogram...

barplot(rev(table(x)))

will do it, or - allowing more general level shuffling - 

barplot(table(factor(x,levels=c("c","b","a"))))

or 

barplot(rev(sort(table(x))))

if you want the columns by decreasing frequency.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list