s-news
[Top] [All Lists]

Re: Trellis: second y-axis with different scale?

To: "'FolkesM@pac.dfo-mpo.gc.ca'" <FolkesM@pac.dfo-mpo.gc.ca>, s-news@wubios.wustl.edu
Subject: Re: Trellis: second y-axis with different scale?
From: "Austin, Matt" <maustin@amgen.com>
Date: Mon, 14 Nov 2005 20:22:25 -0800
One way would be to scale the two values, plot them together and then rescale the vertical axis.  I'm not sure how you would want to label the vertical axis to be clear, but here is one example:
 
 
n      <- 100
day    <- rep(1:n, 2)
var1   <- c(cumsum(rnorm(n)), cumsum(rnorm(n, 2, 2)))
var2   <- c(cumsum(rnorm(n, 5, 2)),cumsum(rnorm(n, 5, 2)))
group  <- rep(letters[1:2], each=n)

var1.s <- scale(var1)
var2.s <- scale(var2)
 
axisVals <- pretty(c(var1.s, var2.s))
 
axisLabels <-  apply( format( round( cbind( axisVals * stdev( var1 ) + mean( var1 ),
                                                              axisVals * stdev( var2 ) + mean( var2 )), 2), scientific = FALSE),
                     1,
                     paste, collapse=", ")
 
   xyplot(var1.s ~ day|group,
             panel = function(x, y, subscripts, ..., y2 = var2.s){
              
               panel.xyplot(x, y, subscripts, ...)
               lines(x, y2[subscripts])
              
             },
             type   = 'l',
             scales = list( y = list( at = axisVals, labels = axisLabels )),
             ylim   = range(axisVals), #range(c(var1.s, var2.s ) ),
             ylab   ='Var1, Var2',
             xlab="Day")
 
 
 
--Matt
-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu]On Behalf Of FolkesM@pac.dfo-mpo.gc.ca
Sent: Monday, November 14, 2005 5:55 PM
To: s-news@wubios.wustl.edu
Subject: [S] Trellis: second y-axis with different scale?

Is it possible to generate trellis plots with a completely different scale on axis 4?  i.e. I've got two time series to plot (superpose) and they have very different Y scales. There is a conditioning component too, so I'd like to stick to trellis.

Thanks!
Michael

<Prev in Thread] Current Thread [Next in Thread>