Skip to content

setting breaks in hist

3 messages · Erin Hodgess, Bill Venables, S Ellison

#
Dear R People:

Is there a way to "guarantee" that breaks=n will give you exactly n
breaks, please?

I'm fairly certain that the answer is "no", but thought I'd check.

Thanks,
Erin
#
The way to guarantee a specific number of panels in the histogram, say n, is to specify n+1 breaks which cover the range of the data.  As far as I know this is the only way.

Bill Venables.

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Erin Hodgess
Sent: Tuesday, 21 June 2011 10:17 AM
To: R help
Subject: [R] setting breaks in hist

Dear R People:

Is there a way to "guarantee" that breaks=n will give you exactly n
breaks, please?

I'm fairly certain that the answer is "no", but thought I'd check.

Thanks,
Erin
#
Not according to the help page. 

Bit kludgy,but try something like

y <- rnorm(73, 17.2)

nbreaks <- function(x, n) {
     r <- range(pretty(y))
    seq(r[1], r[2], length.out=n+1)
}

hist(y, breaks=nbreaks(y,13))
This email and any attachments are confidential. Any use...{{dropped:8}}