[R] 3 levelplots and 1 colorbar

Deepayan Sarkar deepayan.sarkar at gmail.com
Sat Mar 27 05:36:34 CET 2010


On Fri, Mar 26, 2010 at 6:35 PM, Joaquin Rapela <rapela at usc.edu> wrote:
> A single multipanel levelplot would be perfect, but from the help to wireframe
> I understood that conditioning was not possible when the argument to levelplot
> was a matrix.

Why would you see the help for wireframe when you are using levelplot?
(See below.)

> If it is possible please let me know.

But it's not too difficult to convert the data into a data.frame,
which has no such restriction. There are many ways to do the
conversion; one is something along the lines of

framedf <- as.data.frame.table(frame)
framedf$Freq1 <- rnorm(48 * 16) ## etc.
levelplot(Freq + Freq1 ~ Var1 + Var2, framedf)

But also note the following in ?levelplot:

          Both ‘levelplot’ and ‘wireframe’ have methods for ‘matrix’,
          ‘array’, and ‘table’ objects, in which case ‘x’ provides the
          ‘z’ vector described above, while its rows and columns are
          interpreted as the ‘x’ and ‘y’ vectors respectively.  This is
          similar to the form used in ‘filled.contour’ and ‘image’.
          For higher-dimensional arrays and tables, further dimensions
          are used as conditioning variables.

which means you can do the following:

frame3 <- array(rnorm(16 * 48 * 3), c(16, 48, 3))
levelplot(frame3)

>
>> help(wireframe)
>> ...
>> For 'wireframe', 'x', 'y' and 'z' may also be matrices (of
>> the same dimension), in which case they are taken to
>> represent a 3-D surface parametrized on a 2-D grid (e.g., a
>> sphere). Conditioning is not possible with this feature. See
>> details below.

But that's an entirely different case, only applicable to wireframe,
where in a formula z ~ x + y, 'x', 'y', and 'z' are ALL matrices.

-Deepayan



More information about the R-help mailing list