s-news
[Top] [All Lists]

RE: [S] Re: Trellis superpose question

To: "'anne.york@noaa.gov'" <anne.york@noaa.gov>, s-news@wubios.wustl.edu
Subject: RE: [S] Re: Trellis superpose question
From: "Rouwenhorst, Geert" <k.rouwenhorst@yale.edu>
Date: Wed, 26 Jan 2000 22:20:10 -0500
Sender: owner-s-news@wubios.wustl.edu
L;

K. Geert Rouwenhorst
Professor of Finance
Deputy Director International Center for Finance
Yale School of Management
Box 208200
New Haven CT 06520-8200
phone (203) 432 6046
fax (203) 432 9994
k.rouwenhorst@yale.edu
http://mayet/som.yale.edu/~geert/

-----Original Message-----
From: anne.york@noaa.gov [mailto:anne.york@noaa.gov]
Sent: Wednesday, January 26, 2000 7:19 PM
To: s-news@wubios.wustl.edu
Subject: [S] Re: Trellis superpose question 




FOllowing the suggestions of Bill Venables and Bert Gunter, I have come up
with a solution to this problem (original question appended below). I
include 2 function: panel.superpose.lowess and lowmiss (which is called by
panel.superpose.lowess,  in case there are any missing values in the
original data set). 
Cheers,
Anne

++++++++++++++++++++++++++++++++++++++++++++++++++++++
"panel.superpose.lowess" <- function(x, y, subscripts, groups, 
        lwd = superpose.line$lwd, lty = superpose.line$lty, 
        font = superpose.symbol$font, col = NULL, f = 2/3, 
        ...)
{
# this function was cobbled from panel.superpose 
# -- aey 1/26/2000

        superpose.symbol <- trellis.par.get("superpose.symbol")
        superpose.line <- trellis.par.get("superpose.line")
        groups <- as.numeric(as.factor(groups))[subscripts]
        max.groups <- max(groups)
        lty <- rep(lty, length = max.groups)
        lwd <- rep(lwd, length = max.groups)
        font <- rep(font, length = max.groups)
        if(is.null(col)) {
                sl <- rep(superpose.line$col, length = max.groups)
                ss <- rep(superpose.symbol$col, length = max.groups)
                col <- numeric(max.groups)
                for(i in 1:max.groups)
                        col[i] <- sl[i]
        }
        else col <- rep(col, length = max.groups)
        N <- seq(along = groups)
        for(i in sort(unique(groups))) {
                which <- N[groups == i]        
        #                j <- which[order(x[which])]        # sort in x
                j <- which        # no sorting
                lines(lowmiss(x[j], y[j], f = f), col = col[i], 
                lwd = lwd[i], lty = lty[i])
        }
}


"lowmiss" <- function(x, y, f = 2/3)
{
        yes <- x != "NA" & y != "NA"
        lowess(x[yes], y[yes], f)
}


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Anne E. York
National Marine Mammal Laboratory
Seattle WA 98115-0070  USA
e-mail: anne.york@noaa.gov
Voice: +1 206-526-4039
Fax: +1 206-526-6615
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Wed, 26 Jan 2000, Anne York wrote:

>I'm trying to do a trellis xyplot of the form y~x|z with different plotting
>symbols for the levels across a 4th variable. In addition, I would like to
>superimpose a smooth in each panel for each level of the 4th variable.
>
>Here are the commands that I have used. There are no missing values for wt,
>doy, sex, or country. sex is factor with 2 levels (M and F); country is
>factor with 2 levels (US and Ru): 
>
>
>xyplot(wt~doy|sex,groups= country,
> data=combwt,
> panel=function(x,y,subscripts,...){
>  panel.superpose(x,y,subscripts,pch=1:2,...)
>  panel.loess(x,y,subscripts,lty=1:10,...)},
>layout=c(1,2),aspect=.6,
>xlab="Day of year",ylab="Mass (kg)"
>)
>
>I receive the following error message:
>
>Too many values for parameter lty; some ignored
>Error in lines: Invalid argument name: groups
>
>This script works if I don't try to do the panel.loess-- but then I don't
>get the superimposed smooths. Perhaps panel.loess doesn't like
>the groups argument??? Can someone tell me how to use trellis to get the
>smooths  superimposed? 
>
>A long time ago (before Trellis) I wrote an Splus function that does these
>chores. However, it doesn't have the capability of reading formulas, using
>data frames, subsets, etc.
>
>Anne 
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>Anne E. York
>National Marine Mammal Laboratory
>Seattle WA 98115-0070  USA
>e-mail: anne.york@noaa.gov
>Voice: +1 206-526-4039
>Fax: +1 206-526-6615
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>






-----------------------------------------------------------------------
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
-----------------------------------------------------------------------
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

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