[S] subsetting trellis plots and strip size.

Marcus Davy (hramwd@grunt.marc.cri.nz)
Mon, 9 Mar 1998 14:16:04 +1300 (NZDT)


Hello, I have a trellis question about making trellis plot sizing the same
if you create a plot and then a subset of that dataset.

I am using S-Plus, Version 3.4 Release 1 for Sun SPARC.

I am using the "singer" data and the "example.normal.qq" to illustrate the
problem. If you plot this data ("example.normal.qq()") you get a 4 * 2 array
of panels. What I want to do is take a 2 * 1 subset of panels and make the
second plot exactly the same size in perspective by altering the plotting region
with the arguement "pos" in "print.trellis". I subsetted on two levels of
the singer2$voice.part, "Bass 1", and "Bass 2".

The problem is you have no control (as I understand it) with the character size
and height of strips for each panel in trellis (maybe this has already been added
into the functionality of trellis in S-Plus 4.0 for windows).

Try this function I made to see the difference in strip heights,
printed on a "trellis.device(motif)" in landscape mode:

> example.normal.qq(1)
> example.normal.qq(2)

example.normal.qq <-
function(choice=1){
if(choice==1){
# 1) Original example qqnorm on singer data

plotobj <- qqmath( ~ height | voice.part, data = singer, prepanel = prepanel.qqmathline,
scales = list(y = list(at = seq(55,80,by =5)), labels = seq(55,80,by =5)),
panel = function(x, y)
{
panel.grid()
panel.qqmathline(y, distribution = qnorm)
panel.qqmath(x, y)
}
, layout = c(2, 4), aspect = 1, xlab = "Unit Normal Quantile", ylab =
"Height (inches)", ylim = c(55,80))

print.trellis(plotobj)

}
if(choice==2){
# 2) Subsetting the singer data for Bass1, and Bass2.

singer2 <- singer[singer$voice.part=="Bass 1" | singer$voice.part =="Bass 2",]

# Reassigning factor levels so 6 panels of empty data do not get plotted

singer2$voice.part <- factor(as.character(singer2$voice.part), levels = c("Bass 2", "Bass 1"))

# 3) 2 * 1 plot of singer subset.

plotobj <- qqmath( ~ height | voice.part, data = singer2, prepanel = prepanel.qqmathline,
,scales = list(y = list(at = seq(55,80,by =5)), labels = seq(55,80,by =5)),
panel = function(x, y)
{
panel.grid()
panel.qqmathline(y, distribution = qnorm)
panel.qqmath(x, y)
}
, layout = c(2, 1), aspect = 1, xlab = "Unit Normal Quantile", ylab =
"Height (inches)", ylim =c(55,80))

print.trellis(plotobj, pos = c(0.27, 0.25, 0.73, 0.75))
}
invisible()
}

The second subsetted plot has larger strip heights. If you subset from an even larger
array you can get unreasonably large strip heights and character sizes compared to
the first graph.

I had a workaround by adding a "browser()" into "render.trellis" at about line 309
just after the list "save" was made:

> save <- list(rows = rows, columns = columns, y.margin
> = y.margin, x.margin = x.margin, gaps.x =
> gaps.x, gaps.y = gaps.y, cex.strip = cex.strip,
> cex.x = cex.x, cex.y = cex.y,
> strip.labels.width = strip.labels.width)
> browser()
> assign("lastsave", save, where=1)

I then saved the list as another object "lastsave" and updated the list on the
second plot to look like the first plots list when the browser was called inside
"render.trellis". The line I updated the list with was:

> save[c("y.margin","x.margin", "cex.strip","cex.x","cex.y","strip.labels.width")]
+ <- lastsave[c("y.margin","x.margin", "cex.strip","cex.x","cex.y","strip.labels.width")]

If you alter the list on the second plot to look exactly like the first (apart from
leaving a few parameters alone like save$rows and save$columns, you can create
pretty much identical sized plots.

The height of the strips can be altered by modifying the "strip.labels.width" parameter.

Does anyone have a patch for "strip.default" and I guess "render.trellis"
to alter strip character size and strip height from within a trellis plot call
which would make this sort of thing a little easier?

marcus
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news