[R] disappointed with x-axes in hist and density plots

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Jun 17 21:02:37 CEST 2004


"Rishi Ganti" <rishi at iqmail.net> writes:

> Thanks, but even with axis() I can't get the x-axis to extend to the sides.
> 
> Try, e.g., 
> 
> x = rnorm(1000)
> 
> you should have some values in excess of 3 (or below -3).
> 
> I want to draw the x-axis from -4 to 4, thus encapsulating all points.
> 
> axis(1,-4:4)
> 
> but it won't draw. It TRIES to draw it, but I don't see a -4 or 4 on the plot.

Well, the x limits likely don't extend that far. (You have noticed by
now that the axis extents are not the same as the sides of the
bounding box, right?) So set them:

hist(x,xlim=c(-4,4))

Or generically: hist(x,xlim=range(pretty(x))) tends to give the kind
of external axis that you're requesting. Less efficient use of space
though (since the axis is always longer than it needed to be).


-- 
   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




More information about the R-help mailing list