| 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
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Trellis: second y-axis with different scale?, FolkesM |
|---|---|
| Next by Date: | Survival analysis with two mutually exclusive events, Siwik, Thomas (DE - Duesseldorf) |
| Previous by Thread: | Trellis: second y-axis with different scale?, FolkesM |
| Next by Thread: | Survival analysis with two mutually exclusive events, Siwik, Thomas (DE - Duesseldorf) |
| Indexes: | [Date] [Thread] [Top] [All Lists] |