How to set ylim for xyplot of a zoo object (lattice)

I have a zoo object that looks like this:

z <- structure(c(6, 11, 3.6, 8.4, 8.9, 0, NA, 0.5, 7, NA, 9, NA),
    .Dim = c(6L, 2L), .Dimnames = list(NULL, c("2234", "2234.1")), index = structure(c(-17746, -17745, -17744, -17743, -17742, -17741), class = "Date"),
    class = "zoo")

I tried using a grid to plot both columns simultaneously in two different panels:
xyplot(z)

This gives me the same x axis for both panels, but different from ylim. I want them to have the same name, so I tried it xyplot(z, ylim=range(z[,1])), it didn’t do anything, therefore, after reading "Plot zoo Series with Lattice", I tried it trellis.focus("panel", 2,1,ylim=range(z[,1]))too without any luck ...

This is probably easy to do, but I find the lattice package very difficult to use (at least for starters). Can anyone help?

Thank!

+3
source share
2 answers

Give it a try xyplot(z, ylim=range(z, na.rm=TRUE)).

There are two things:

  • na.rm=TRUE range
  • range(z) range(z[,1]) , .

require(lattice)
require(zoo)
z <- zoo(cbind(a=1:4,b=11:14), Sys.Date()+(1:4)*10)
xyplot(z, ylim=range(z, na.rm=TRUE))

It works

: R 2.13.0, zoo_1.6-5, lattice_0.19-26

+3

xyplot.zoo xyplot, :

xyplot(z, scales = list(y = list(relation = "same")))

:

xyplot(z, scales = list(y = list(relation = "same", alternating = FALSE)))
+2

All Articles