[R] comparing 3 datasets

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed Jun 20 08:36:04 CEST 2001


On Tue, 19 Jun 2001, Deepayan Sarkar wrote:

[...]

> An xlim argument should set the same limits for all
> the
> histograms. Change your function to:

Unfortunately not so.  The critical lines in hist.default are

        rx <- range(x)
        breaks <- pretty(rx, n = nnb, min.n = 1)

so the breaks depend on the range of the data and not on xlim.

Jon Baron had the better idea: use a grid for breaks.  So something like

rz <- range(s1[[var]], s2[[var]], s3[[var]])
breaks <- pretty(rz, 40)

...
hist(s1[[var]], breaks, xlab=var)

>
>
> histomatic <- function (s1,s2,s3,var){
>    if (is.numeric (s2[[var]])) {
>    par(mfrow=c(3,1));
>    xlim <- range(s1[[var]], s2[[var]], s3[[var]]);
>    hist(s1[[var]], breaks=40,xlab=var, xlim = xlim);
>    hist(s2[[var]], breaks=40,xlab=var, xlim = xlim);
>    hist(s3[[var]], breaks=40,xlab=var, xlim = xlim);
> }
>

[...]

Another idea: use truehist() in package MASS, which wants the grid spacing,
not the number of breaks.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list