Re: [R] Barplot

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Wed 18 Oct 2006 - 17:30:00 GMT

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

______________________________________________
R-help@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.
Received on Thu Oct 19 10:32:02 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 19 Oct 2006 - 01:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.