Hi: The y axis on the hist function seems to set its limits oddly. sometimes, it covers the full range of the data and sometimes it stops one major tick short. I have had this behavior with a variety of data sets, and it can easily be reproduced by just running the following several times: hist(rnorm(100000)) I have tried explicitly setting ylim to the range of values produced by rnorm (taking care to set some variable to rnorm(100000) and then graphing that), and I still get the y axis plotting behvior I just described. TIA, Bud
From: "Bud Gibson" <fpgibson at umich.edu>> The y axis on the hist function seems to set its limits oddly. > sometimes, it covers the full range of the data and sometimes it stops > one major tick short. I have had this behavior with a variety of data > sets, and it can easily be reproduced by just running the following > several times: > > hist(rnorm(100000)) > > I have tried explicitly setting ylim to the range of values produced by > rnorm (taking care to set some variable to rnorm(100000) and then > graphing that), and I still get the y axis plotting behvior I just > described.I'm not sure I understand the problem correctly. Doesn't the following seem to correct the y-axis problem? hist(rnorm(100000),ylim=c(0,25000)) Dan daniel_ho at harvard.edu
Bud Gibson <fpgibson at umich.edu> writes:> Hi: > > The y axis on the hist function seems to set its limits oddly. > sometimes, it covers the full range of the data and sometimes it stops > one major tick short. I have had this behavior with a variety of data > sets, and it can easily be reproduced by just running the following > several times: > > hist(rnorm(100000)) > > I have tried explicitly setting ylim to the range of values produced > by rnorm (taking care to set some variable to rnorm(100000) and then > graphing that), and I still get the y axis plotting behvior I just > described.I don't think this is stranger than the axes on any other plots. It's just that the bounding box isn't printed on histograms. Try adding a box() and you'll see what the issue is. To ensure that the last axis label is "over the top", it is not enough to diddle the ylim to the range of barheights; you'll need to ensure that the ylim is also a pretty value, something like this: z <- rnorm(100000) h <- hist(z,plot=F) plot(h,ylim=range(pretty(range(0,h$counts)))) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
fpgibson at umich.edu said:> The y axis on the hist function seems to set its limits oddly. > sometimes, it covers the full range of the data and sometimes it stops > one major tick short. I have had this behavior with a variety of > data sets, and it can easily be reproduced by just running the > following several times:> hist(rnorm(100000))If you use instead: hist(rnorm(100000)); box() You won't notice anything strange, and you may be satisfied with the result. The `problem', if there is a problem, is pretty deep in the command axis() used by histogram plotting function plot.histogram(), and the behaviour is just same as in other R graphs which do not necessarily have tic marks at the axis extremes. You can see if you execute sequentially: plot(rnorm(100), rnorm(100), axes=FALSE) axis(1); axis(2) box() So it's a property, and using box() is the easiest way to hide this property, if you don't like it. cheers, jari oksanen -- Jari Oksanen -- Dept Biology, Univ Oulu, 90014 Oulu, Finland Ph. +358 8 5531526, cell +358 40 5136529, fax +358 8 5531061 email jari.oksanen at oulu.fi, homepage http://cc.oulu.fi/~jarioksa/