The syntax below creates parallel time-series plots of three different y 
variables conditioned by a dichotomous factor.  (Thanks to several people who 
answered an earlier post from Thursday, 
http://tolstoy.newcastle.edu.au/R/e9/help/10/02/3848.html. The syntax below is 
based on their helpful replies.)

The y variables differ wildly in their scales, and the specification

scales$y$relation="free"

enables each y variable to be plotted on its own distinct scale.  Unfortunately, this also causes 
the scales of the *same* y variable to differ between the two levels of the dichotomous factor. 
Thus one does not easily see (for instance) that QQQ takes on much smaller values for 
"feline" than for "Dog".

Is there a way to lock the levels of the factor (the columns) into the same 
scale for each y variable (for each row), while allowing the scales to differ 
between the y variables (between the rows)?

#       Toy data to illustrate:

N<-15
w <- (1:N)/N
x <- w^2
QQQ <- exp(w)
z <- x / QQQ
JUNK<-data.frame( x=x, QQQ=QQQ, z=z, w=w)
JUNK$ID<-1
jank<-JUNK
jank$ID<-2
jank$x<-jank$x / 2
jank$QQQ<-jank$QQQ / 2
jank$z<-jank$x/jank$QQQ
JUNK<-rbind(JUNK, jank)
jank<-JUNK
jank$x<-(jank$x) ^(1/4)
jank$QQQ<-(jank$QQQ) / 100000
jank$z <- jank$x / jank$QQQ
JUNK$Species<-"Dog"
jank$Species<-"feline"
JUNK<-rbind(JUNK, jank)
JUNK$Species<-factor(JUNK$Species)
JUNK$ID<-factor(JUNK$ID)
summary(JUNK)


#       The three commands below differ only in the value of scales$y$relation.

# scales$y$relation="same" # forces x, QQQ, and z to the same scale, which obscures signal.
#       But at least it enables us to see that the range of QQQ
#       differs immensely between Dog and feline.
xyplot ( x + QQQ + z ~ w | Species
        , group=ID
        , data=JUNK
        , ylab=c("x (mg/L)", "QQQ (pg/L)", "z (mIU/mL)")
        , xlab=c("Dog", "feline")
        , type="o"
        , strip= TRUE
        , outer=TRUE
        , layout=c(2,3)
        , scales=list(
                x=list( alternating=3)
                , y=list(
                        relation="same"
                        , alternating=3
                        , rot=0
                        , log=T
                        )
                )
        )


# scales$y$relation="free" # displays x, QQQ, and z on different scales, but it also allows
#       the scales for each variable to differ between Dog and feline.
#       This prevents us from visually comparing the species.
xyplot ( x + QQQ + z ~ w | Species
        , group=ID
        , data=JUNK
        , ylab=c("x (mg/L)", "QQQ (pg/L)", "z (mIU/mL)")
        , xlab=c("Dog", "feline")
        , type="o"
        , strip= TRUE
        , outer=TRUE
        , layout=c(2,3)
        , scales=list(
                x=list( alternating=3)
                , y=list(
                        relation="free"
                        , alternating=3
                        , rot=0
                        , log=T
                        )
                )
        )


# scales$y$relation="sliced" # shows us that the difference max(z)-min(z) differs greatly between
#       Dog and feline.  But it obscures the fact that
#       QQQ differs wildly between Dog and feline, as we saw when
#       relation="same".
xyplot ( x + QQQ + z ~ w | Species
        , group=ID
        , data=JUNK
        , ylab=c("x (mg/L)", "QQQ (pg/L)", "z (mIU/mL)")
        , xlab=c("Dog", "feline")
        , type="o"
        , strip= TRUE
        , outer=TRUE
        , layout=c(2,3)
        , scales=list(
                x=list( alternating=3)
                , y=list(
                        relation="sliced"
                        , alternating=3
                        , rot=0
                        , log=T
                        )
                )
        )


#       In comparing these plots, we also see that, of necessity, it is only with 
relation="same"
#       that we can avoid repeating the y axis ticks for
#       the second column of panels. With relation="same", xyplot
#       automatically gets rid of that repetition.  And we see an example of 
the fact that
#       scales$alternating=3 only works when relation="same".

Thanks for any insight

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
U.S.A.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to