Skip to content

How to create following chart for visualizing multivariate time series

4 messages · David Winsemius, Henrique Dallazuanna, jim holtman

#
"Henrique Dallazuanna" <wwwhsd at gmail.com> wrote in
news:da79af330802290329y4c0ad78fkc483303229a868ae at mail.gmail.com: 

library(lattice)
levelplot(r, colorkey=list(col=gray((0:32)/32)),
     col.regions=(col=gray((0:32)/32)))

When I try that example, I get an error, even after updating lattice.
+  col.regions=(col=gray((0:32)/32)))
Error in UseMethod("levelplot") : no applicable method for "levelplot"

If I simply change colorkey=FALSE to colorkey=TRUE in the first levelplot 
help page example, I have what looks to me as "success".

levelplot(z~x*y, grid, cuts = 50, scales=list(log="e"), xlab="",
          ylab="", main="Weird Function", sub="with log scales",
          colorkey = TRUE,
          region = TRUE)
#
This works for me:

x <- y <- seq(-4*pi, 4*pi, len=27)
r <- sqrt(outer(x^2, y^2, "+"))
library(lattice)
levelplot(r, colorkey=list(col=gray((0:32)/32)),
    col.regions=(col=gray((0:32)/32)))

'r' is a matrix for you?
On 01/03/2008, David Winsemius <dwinsemius at comcast.net> wrote:

  
    
#
"Henrique Dallazuanna" <wwwhsd at gmail.com> wrote in
news:da79af330803011508u4cd31c96j9584ace16cca697e at mail.gmail.com:
Works for me as well.
It was the vector created by the first levelplot() example. I had not 
run the code of Megh Dal. 

When I hastily looked at the help page and saw that "colorkey" was 
supposed to be a logical, I assumed that the list argument was throwing 
the error. If I had read the full text I would have seen that a list 
argument was also valid. This gives what appears to me to be identical 
success, but maybe it has risks that I don't understand:

levelplot(r, colorkey=TRUE,
     col.regions=(col=gray((0:32)/32)))

Thanks;
David Winsemius
#
If you want color, then a slight addition to Henrique's solution will do it:

x <- y <- seq(-4*pi, 4*pi, len=27)
r <- sqrt(outer(x^2, y^2, "+"))
library(lattice)
colkey <- colorRampPalette(c('red','yellow','green'))(32)
levelplot(r, colorkey=list(col=colkey),
   col.regions=(col=colkey))
On Sat, Mar 1, 2008 at 6:08 PM, Henrique Dallazuanna <wwwhsd at gmail.com> wrote: