[R] Barplot

Chuck Cleland ccleland at optonline.net
Wed Oct 18 19:30:00 CEST 2006


Qian Wan wrote:
> Hi,
> 
> I have about 500 data entry ranging from -50 to 10,000. when I 
> barplot(data), it plots all 500 of them individually. How can I set a 
> ranges to group these 500 numbers into 10 or 20 groups, and plot the 
> value of the ranges with how many numbers are in the range.

Maybe something along these lines:

Y <- c(-50, 10000, sample(-50:10000, size=498, replace=TRUE))

par(mar = c(8, 5, 5, 5))

X <- barplot(table(cut(Y, breaks=c(-50, seq(0, 10000, 1000)),
                       include.lowest=TRUE)), xaxt = "n", xlab = "")

text(X, -2, srt = 45, adj = 1,
     labels = levels(cut(Y, breaks=c(-50, seq(0, 10000, 1000)),
                     include.lowest=TRUE)), xpd = TRUE)

?cut for more details on forming the groups.

  Also, have you considered hist() ?

> Thanks a lot,
> 
> Q.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list