[R] Generating a vector for breaks in a histogram

michael watson (IAH-C) michael.watson at bbsrc.ac.uk
Thu Jul 3 15:02:19 CEST 2003


Hi

I have two lots of numbers which I would like to histogram using the hist() function.  For comparative reasons, I want them to be on the same scale, which I can use the xlim and ylim options to achieve.

However, having them on the same scale is meaningless unless they have the same "breaks".  Consulting the documentation, there are 4 ways of defining the number of breaks, only one of which is "definite", the others merely form suggestions, which I have found is not good enough.

The only definite way is to provide a vector to the hist() function which is a vector of the break points for the histogram.  So I need to generate a vector that contains say, 500, numbers in it, equi-distance apart between a min and a max.  EG:

> myfunc(n=20,min=1,max=20) 

would provide a vector, length 20, with the numbers 1 through 20 in it.

Is there a function in R that can do this?

Thanks
Mick




More information about the R-help mailing list