[R] Questions about histograms

Duncan Murdoch murdoch at stats.uwo.ca
Mon Feb 11 02:36:01 CET 2008


On 10/02/2008 8:14 PM, Andre Nathan wrote:
> Hello
> 
> I'm doing some experiments with the various histogram functions and I
> have a two questions about the "prob" option and binning.
> 
> First, here's a simple plot of my data using the default hist()
> function:
> 
>> hist(data[,1], prob = TRUE, xlim = c(0, 35))
> 
>   http://go.sneakymustard.com/tmp/hist.jpg
> 
> My first question is regarding the resulting plot from hist.scott() and
> hist.FD(), from the MASS package. I'm setting prob to TRUE in these
> functions, but as it can be seen in the images below, the value for the
> first bar of the histogram is well above 1.0. Shouldn't the total area
> be 1.0 in the case of prob = TRUE?
> 
>> hist.scott(data[,1], prob = TRUE, xlim=c(0, 35))

It looks to me as though the area is one.  The first bar is about 3.6 
units high, and about 0.2 units wide: area is 0.72.  There are no gaps 
between bars in an R histogram, so the gaps you see in this jpg are bars 
with zero height.

Duncan Murdoch

> 
>   http://go.sneakymustard.com/tmp/scott.jpg
> 
>> hist.FD(data[,1], prob = TRUE, xlim=c(0, 35))
> 
>   http://go.sneakymustard.com/tmp/FD.jpg
> 
> Is there anything I can do to "fix" these plots?
> 
> My second question is related to binning. Is there a function or package
> that allows one to use logarithmic binning in R, that is, create bins
> such that the length of a bin is a multiple of the length of the one
> before it?
> 
> Pointers to the appropriate docs are welcome, I've been searching for
> this and couldn't find any info.
> 
> Best regards,
> Andre
> 
> ______________________________________________
> 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