Humberto Mohr
2013-Apr-23 17:40 UTC
[R] Strange graphical pattern when using hist() function
Running the following lines I got a strange plot from hist function: x<-0:30 hist(x,breaks=31) As you can see, the 0 value appears two times in the plot. The Y axis only presents 1 as the highest value when: hist(x,breaks=62) Nevertheless, it seems to have two bars between 0 and 1. Could someone please explain to me why it is happening? Many thanks in advance!
Kevin E. Thorpe
2013-Apr-23 18:33 UTC
[R] Strange graphical pattern when using hist() function
On 04/23/2013 01:40 PM, Humberto Mohr wrote:> Running the following lines I got a strange plot from hist function: > > x<-0:30 > hist(x,breaks=31) > > As you can see, the 0 value appears two times in the plot. > The Y axis only presents 1 as the highest value when: > > hist(x,breaks=62) > > Nevertheless, it seems to have two bars between 0 and 1. > > Could someone please explain to me why it is happening? > > Many thanks in advance! >I think if you do print(hist(x,breaks=31)) you will see it. The "zero" bin has the values for zero and one. There are 30 bins, not 31, as I think you are expecting. Take a look at the ?hist to understand how the bins are constructed. -- Kevin E. Thorpe Head of Biostatistics, Applied Health Research Centre (AHRC) Li Ka Shing Knowledge Institute of St. Michael's Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.thorpe at utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016
David Winsemius
2013-Apr-23 18:38 UTC
[R] Strange graphical pattern when using hist() function
On Apr 23, 2013, at 10:40 AM, Humberto Mohr wrote:> Running the following lines I got a strange plot from hist function: > > x<-0:30 > hist(x,breaks=31) > > As you can see, the 0 value appears two times in the plot. > The Y axis only presents 1 as the highest value when: > > hist(x,breaks=62) > > Nevertheless, it seems to have two bars between 0 and 1. > > Could someone please explain to me why it is happening?The function is behaving as described in the help page: "If right = TRUE (default), the histogram cells are intervals of the form (a, b], i.e., they include their right-hand endpoint, but not their left one, with the exception of the first cell when include.lowest is TRUE." -- David Winsemius Alameda, CA, USA