[R] Y-axis range in histograms

(Ted Harding) Ted.Harding at manchester.ac.uk
Mon May 31 17:40:32 CEST 2010

On 31-May-10 14:49:43, Aarne Hovi wrote:
> Hi,
> I'm trying to create a histogram with R. The problem is that the
> frequency is high for a couple of x-axis categories (e.g. 1500)
> and low for most of the x-axis categories (e.g. 50)  
> http://r.789695.n4.nabble.com/file/n2237476/LK3_hist.jpg .
> When I create the histogram, it is not very informative, because
> only the high frequencies can be seen clearly. Is there any way I
> could cut the y-axis from the middle so that the y-axis values
> ranged for example from 0 to 300, and then again from 900 to 1500?

There may be specific rpovision for this in one of the extra graphics
packages, but using plain hist() the only approach I can think of is
on the folllowing lines.

First create the histogram and name it:

  H <- hist(whatever)

Then fake the high counts:

  ix <- H$counts > 400  ## which counts exceed 400 (say)
  H$counts[ix] <- H$counts[ix] - 500 ## counts > 900 -> 400+

Now plot the histogram without y-axis annotations, and with
ylim=c(0,1100); then add annotations (0,100,200,300,900,1000,1100,...).
Finally (perhaps) plot filled white boxes over the histogram bars
with height range 330-370 (say) so that the break is obvious.

Just first thoughts!

E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 31-May-10                                       Time: 16:40:29
------------------------------ XFMail ------------------------------

More information about the R-help mailing list