I have several time series variables, some of the variables have rather large ranges. I want to make a one-page graph with several complex graphs of each variable, some of which are scaled along the log10 y axis. I am relatively new to the grid and could not figure out how to efficiently mix log10 scaling with unsigned axes and get a publication quality graph. If print.trellis is used, the graphs are not aligned, and filling requires some work, if c.trellis is used, the layout is good, but only y-scaling from only one graph is used. Any suggestions for an efficient solution where I can replicate c.trellis output using different y-scaling for each (original) object? Example below:
require(lattice)
require(latticeExtra)
d.date <- as.POSIXct(c("2009-12-15", "2010-01-15", "2010-02-15", "2010-03-15", "2010-04-15"))
CO2dat <- c(100,200,1000,9000,2000)
pHdat <- c(10,9,7,6,7)
tmp <- data.frame(date=d.date ,CO2dat=CO2dat ,pHdat=pHdat)
plot1 <- xyplot(pHdat ~ date, data=tmp
, ylim=c(5,11)
, ylab="pHdat"
, xlab="Date"
, origin = 0, border = 0
, scales=list(y=list(alternating=1))
, panel = function(...){
panel.xyarea(...)
panel.xyplot(...)
}
)
plot2 <- xyplot(CO2dat ~ date, data=tmp
, ylim=c(10,10^4)
, ylab="CO2dat"
, xlab="Date"
, origin = 0, border = 0
, scales=list(y=list(alternating=1,log=10))
, yscale.components = yscale.components.log10ticks
, panel = function(...){
panel.xyarea(...)
panel.xyplot(...)
panel.abline(h=log10(390),col="blue",type="l",...)
}
)
print(plot2, split=c(1,1,1,2), more=TRUE)
print(plot1, split=c(1,2,1,2), more=F)
comb <- c(plot1, plot2, x.same=F, y.same=F, layout = c(1, 2))
update(comb, ylab = c("pHdat","log10 CO2dat"))