s-news
[Top] [All Lists]

using panel.superpose with stripplot

To: <s-news@lists.biostat.wustl.edu>
Subject: using panel.superpose with stripplot
From: "Schwarz,Paul" <PSchwarz@gcrinsight.com>
Date: Wed, 3 May 2006 16:08:51 -0700
Thread-index: AcZvBor/QilWGNogSAep0Mbk86Zwjw==
Thread-topic: using panel.superpose with stripplot
S-News Readers,
 
I'm still somewhat new to Trellis graphics, and I'm interested in
figuring out a way to use the panel.superpose function with the
stripplot function.

For example, consider the Trellis example:

stripplot(voice.part ~ height, data = singer, aspect = 1, jitter = T,
xlab = "Height (in)")


How could I adapt this example if I had two sets of singer data, say for
two different choirs or two different time periods? I've tried two
different approaches:


#1:
# Create a test data set to work with...
singer.tst <- singer
singer.tst$choir <- rep("A", dim(singer)[1])
height.tst <- singer.tst$height + round(runif(dim(singer)[1], -3, 3))
singer.tst <- rbind(singer.tst,
        data.frame(height= height.tst, voice.part=
singer.tst$voice.part, choir= rep("B", dim(singer)[1])))
singer.tst$choir <- factor(singer.tst$choir)

stripplot(voice.part ~ height, groups= choir, data= singer.tst,  xlab=
"Height (in)", 
        panel= function(x, y, ...) {
                panel.superpose(x, y, ...)
        }
)

One problem, though, with this approach is that I can't seem to get the
"jitter" option work. I get the error message "Invalid argument", either
in the call to stripplot or the call to the panel function. Does anyone
know how to make jitter argument work in a "superpose" context?


#2:
The second approach that I've tried is based on creating extra levels
for the factor variable, voice.part, so that differences between the two
choirs can be more easily visualized. Essentially, each choir is
assigned its own set of factor levels.

# Construct a new voice.part factor w/ unique levels for each choir...
voice.part.tst <- as.numeric(singer.tst$voice.part)
voice.part.tst <- ifelse(singer.tst$choir == "A", voice.part.tst*2 - 1,
voice.part.tst*2)
singer.tst$voice.part.tst <- ordered(voice.part.tst, labels=
rep(levels(singer.tst$voice.part), each= 2))

stripplot(voice.part.tst ~ jitter(height), groups= choir, data=
singer.tst,  xlab= "Height (in)",
        panel= function(x, y, ...) {
                panel.superpose(x, y, ...)
        }
)

Does anyone have a better (or easier) way to do this?

Thanks a lot for your time and patience.

-Paul Schwarz

<Prev in Thread] Current Thread [Next in Thread>
  • using panel.superpose with stripplot, Schwarz,Paul <=