[R] Histogram

Sarah Goslee sarah.goslee at gmail.com
Thu Jul 5 21:47:13 CEST 2012


There's no reason you can't do that with normally-distributed data,
though I'm not sure why you'd want to. My point was rather that you
can't specify the bin width and size both. If you let the bin size
vary, this will work:

set.seed(1234)
mydata <- rnorm(1000, mean = 2, sd = 4)
mydata.hist <- hist(mydata, breaks=quantile(mydata, probs=seq(0, 1,
length.out = length(mydata)/50 + 1)))
mydata.hist$counts


Sarah

On Thu, Jul 5, 2012 at 3:37 PM, Jim Silverton <jim.silverton at gmail.com> wrote:
> Thanks Sarah!!
> Ok so if I have say x = runif(1000,0,1) say instead if the normal and I want
> a histogram with bins that have an equal number of observations. For example
> if I want each bin to have 50 observations, how do I do this?
>
>
>
> On Thu, Jul 5, 2012 at 3:34 PM, Sarah Goslee <sarah.goslee at gmail.com> wrote:
>>
>> Hi Jim,
>>
>> You can't specify both number of bins and bin size. You can specify
>> breaks: either the number of bins or the location of breakpoints. A
>> histogram with 20 bins of 50 observations each must by definition come
>> from a uniform distribution.
>>
>> What are you trying to accomplish?
>>
>> Sarah
>>
>> On Thu, Jul 5, 2012 at 3:29 PM, Jim Silverton <jim.silverton at gmail.com>
>> wrote:
>> > I have a column of 1000 datapoints from the normal distribution with
>> > mean 2
>> > and variance 4. How can I get a histogram of these observations with 20
>> > bins with each bin having 50 observations?
>> >
>> > --
>> > Thanks,
>> > Jim.
>>

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list