[R] Histogram

Duncan Murdoch murdoch.duncan at gmail.com
Thu Sep 5 16:41:46 CEST 2013


On 05/09/2013 10:17 AM, David Carlson wrote:
> I wasn't suggesting that much detail, but I think the addition
> of one sentence in the last paragraph of the Details section
> would make it the meaning of "the number is a suggestion only"
> clearer.
>
> "These functions provide a suggested number of bins that may be
> modified to produce 'round' breakpoints covering the range of
> the values in x."

I think that's the wrong place for it (since breaks=10 is perfectly 
fine, but is not a function).  I'll change the initial sentence to say:

In the last three cases the number is a suggestion only; the
      breakpoints will be set to \code{\link{pretty}} values.

If people want to know what pretty values are, they can follow the link.

Duncan Murdoch

>
> Added just before the last sentence, "Alternatively, . . ."
>
> Also pretty() could be added to the See Also section.
>
>
> David Carlson
>
> -----Original Message-----
> From: Duncan Murdoch [mailto:murdoch.duncan at gmail.com]
> Sent: Wednesday, September 4, 2013 7:00 PM
> To: dcarlson at tamu.edu
> Cc: 'philippe massicotte'; 'Rui Barradas';
> 'r-help at R-project.org'
> Subject: Re: [R] Histogram
>
> On 13-09-04 4:44 PM, David Carlson wrote:> Good question. It
> turns out
> that the manual page does not tell
>   > the whole story.
>
> Do you really think the manual page would be improved if it went
> into as
> much detail as you give below?  It does say clearly that breaks
> is a
> "suggestion only".  I don't think it would be clearer if it
> explained
> exactly how the suggestion is used. It would just be more
> complicated,
> and less likely to be read.
>
> Duncan Murdoch
>
>
>    Looking at the source code for hist.default,
>   > the function starts with the number of breaks suggested by
>   > nclass.Sturges(), but then this number (or any other number
> of
>   > breaks that you specify) is passed to pretty() along with the
>   > maximum and the minimum values of the data (ie range(data))
> to
>   > create "pretty" break intervals. In your example,
>   > nclass.Sturges() always recommends 8 breaks, but the number
> of
>   > the breaks changes based on the minimum and maximum values.
> So
>   > the only way to get exactly the number of breaks you want is
> to
>   > specify the break intervals yourself.
>   >
>   > David Carlson
>   >
>   >
>   > -----Original Message-----
>   > From: r-help-bounces at r-project.org
>   > [mailto:r-help-bounces at r-project.org] On Behalf Of philippe
>   > massicotte
>   > Sent: Wednesday, September 4, 2013 3:02 PM
>   > To: Rui Barradas
>   > Cc: r-help at R-project.org
>   > Subject: Re: [R] Histogram
>   >
>   > Thank you everyone.
>   > Try executing this:
>   > replicate(100, length(hist(rnorm(100), nclass = 10)$counts))
>   > I'm still not sure why the number of bins (classes) is not
>   > consistent.
>   > Thank in advance.
>   >
>   >> Date: Wed, 4 Sep 2013 20:27:36 +0100
>   >> From: ruipbarradas at sapo.pt
>   >> To: pmassicotte at hotmail.com
>   >> CC: r-help at r-project.org
>   >> Subject: Re: [R] Histogram
>   >>
>   >> Hello,
>   >>
>   >> See the arguments 'right' and 'include.lowest' of ?hist.
>   >> To give what you want, try instead
>   >>
>   >> h1 <- hist(1:10, 10)  # counts are 2, 1, 1, ...
>   >> h2 <- hist(1:10, breaks = 0:10)  # all counts are 1
>   >>
>   >>
>   >> and see the difference between h1 and h2, components
> 'breaks'
>   > and 'counts'.
>   >>
>   >> Hope this helps,
>   >>
>   >> Rui Barradas
>   >>
>   >> Em 04-09-2013 19:34, philippe massicotte escreveu:
>   >>> Hi everyone.
>   >>> I'm currently translating some Matlab code into R. However,
>   > I realized that the hsit function produce different results
> in
>   > both languages.
>   >>> in Matlab, hist(1:10, 10) will produce 10 bins with a count
>   > of 1 in each, but in R it will produce 9 classes with count
> of
>   > 2,1,1,1,1,1,1,1,1.
>   >>> I'm a bit embarrassed to ask such question, but why R is
> not
>   > producing 10 classes as requested?
>   >>> Thanks in advance,Phil 		 	   		
>   >>> 	[[alternative HTML version deleted]]
>   >>>
>   >>> ______________________________________________
>   >>> R-help at r-project.org 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.
>   >>>
>   >   		 	   		
>   > 	[[alternative HTML version deleted]]
>   >
>   > ______________________________________________
>   > R-help at r-project.org 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.
>   >
>   > ______________________________________________
>   > R-help at r-project.org 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.
>   >
>
>



More information about the R-help mailing list