How to set ylim for a 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 to use lattice to plot both columns at the same time in 2 different panels:
开发者_运维技巧xyplot(z)
This gives me the same x axis for both panels but different ylim. I want them to have the same ylim so I tried xyplot(z, ylim=range(z[,1]))
it didn't do anything, so after reading "Plot zoo Series with Lattice" I tried trellis.focus("panel", 2,1,ylim=range(z[,1]))
also without any luck...
This is probably an easy thing to do but I am finding the lattice package very hard to use (at least to start with). Can anyone help?
Thanks!
Try xyplot(z, ylim=range(z, na.rm=TRUE))
.
There are two things:
na.rm=TRUE
causerange
to work properlyrange(z)
instead ofrange(z[,1])
let you handling range of all data, not just one column.
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))
Note: R version 2.13.0, zoo_1.6-5, lattice_0.19-26
xyplot.zoo
accepts most xyplot
arguments so:
xyplot(z, scales = list(y = list(relation = "same")))
or this variation:
xyplot(z, scales = list(y = list(relation = "same", alternating = FALSE)))
精彩评论