[R] lattice and histogram

Deepayan Sarkar deepayansarkar at yahoo.com
Sat Jul 28 20:29:36 CEST 2001

--- Ted.Harding at nessie.mcc.ac.uk wrote:
> Hello again folks,
> Thanks to all for the advice on getting hold of
> "grid"
> and "lattice". I think I'm getting the hang of it.
> This produces very satisfying arrays of histograms.
> The typical command I am using is
>   histogram( ~ DATA.df$X | DATA.df$F, \
>              type=c("count"), layout=c(5,5) )

A more typical and elegant usage would be

histogram(~X|F, data = DATA, [...])

> For some variables, say again typically "X", for one
> (or sometimes more) level of "F" all values of "X"
> are
> missing (coded as "NA" in the data file).
> If I run the above command with such a variable "X",
> I get
> Error in if (lim[1] > lim[2]) stop("Improper value
> of limit") ;
>         missing value where logical needed
> There is no problem if, at given level of "F", "X"
> is a mixture
> of good values and "NA"s; it seems to do the right
> thing by
> simply ignoring the latter. It's the case of "data =
> empty set"
> that seems to cause the trouble.

This is definitely a bug, which should be fixed in the
next release of lattice. For now, what I can suggest
is to change a couple of lines in the histogram()
function. Replace

xlim.l <- min(xlim.l, tem$xlim[1])
xlim.u <- max(xlim.u, tem$xlim[2])


xlim.l <- min(xlim.l, tem$xlim[1], na.rm = TRUE)
xlim.u <- max(xlim.u, tem$xlim[2], na.rm = TRUE)

This should take care of your problem, though there
still might be some other similar loopholes.

PS: variable names like F might cause problems, since
a lot of the lattice code use F/T instead of
FALSE/TRUE. Again, this should not be so, and will be
fixed in the next release.

Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
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