[R] Setting xlim in lattice plots

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Mar 16 10:58:57 CET 2006


On 3/16/06, Mike White <mikewhite.diu at btconnect.com> wrote:
> Sundar
> Thanks, that is what I needed, but is it possible to customise the xlim
> ranges for individual plots and if so how do I convert the dataframe of
> range values to the list format required by the histogram fuction?

It's possible to supply a list for 'xlim'. With your original example,
a suitable list would be produced by

limits <- do.call(c, apply(mat, 2, function(x) list(c(0, max(x)))))

which is somewhat convoluted because apply doesn't have a SIMPLIFY
argument like sapply.

Note that another alternative for systematic calculations such as this
is the use of a prepanel function; e.g.

densityplot(~values | ind, mat2,
            prepanel = function(x, ...) {
                list(xlim = c(0, max(x, na.rm = TRUE)))
            },
            scales = "free")

Deepayan




More information about the R-help mailing list