s-news
[Top] [All Lists]

Re: key and margins problem when using xyplot

To: "Sebastien Bihorel" <Sebastien.Bihorel@cognigencorp.com>, <s-news@lists.biostat.wustl.edu>
Subject: Re: key and margins problem when using xyplot
From: "Samer Mouksassi" <smouksassi@Pharsight.com>
Date: Wed, 17 Dec 2008 13:52:35 -0800
In-reply-to: <49496B1D.2090303@cognigencorp.com>
References: <49496A25.8000206@cognigencorp.com> <49496B1D.2090303@cognigencorp.com>
Thread-index: AclgjDwDaBNso9EgR5WKUmKZ363uNQABUFHA
Thread-topic: [S] key and margins problem when using xyplot

Hello Sebastien,

 

 

par(oma=c(3,6,1,2),xpd=T) # xpd to be able to plot outside the plot region and oma to change the                       #                   spaces of the margins

xyplot(b~a|ID,

     data=""

     panel=function(x,y,subscripts){

       panel.xyplot(x, y, pch=16)

       panel.xyplot(mydf$a[subscripts],mydf$c[subscripts],pch=3)

       },

       as.table=T,

       subscripts=T,

       key = list(space="bottom", x=0.5,y=-0.2,

       transparent = T,

       text=list(c("b", "c")),

       lines = list(pch = c(16,3), type = c("p", "p"))),

     )

You can have it on the “top” side without any overlap.

 

Hope this helps,

 

Thank you,

 

Samer


From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Sebastien Bihorel
Sent: 2008-12-17 16:12
To: s-news@lists.biostat.wustl.edu
Subject: Re: [S] key and margins problem when using xyplot

 

Dear S-users,

I have a hard time finding a solution to the following problem. I have this function which, among others things, creates and print a trellis plot created with xyplot. Different data.frame objects are sent to this function along with others variables. Everything would be fine if only the legend of my plot was not displayed on top of my X-axis title (see sample script below). Is there a way to increase the margin for the key, or should I specify the key differently?

Thanks in advance for your advises.

myfcn <- function(mydf){
  assign("mydf",mydf,frame=1)

   myplot<-xyplot(b~a|ID,
     data=""
     panel=function(x,y,subscripts){
       panel.xyplot(x, y, pch=16)
       panel.xyplot(mydf$a[subscripts],mydf$c[subscripts],pch=3)
       }
,
       as.table=T,
       subscripts=T,
       key = list(space="bottom",
        transparent = T,
        text=list(c("b", "c")),
        lines = list(pch = c(16,3), type = c("p", "p"))),
     )

   print(myplot)
}

a <- rep((1:10),times=2)
b <- rep((11:20),times=2)
c <- rep((20:11),times=2)
ID<- rep((1:4), each =5)

mydf<-data.frame(a,b,c,ID)

myfcn(mydf)

Sebastien Bihorel, PharmD, PhD
PKPD Scientist
Cognigen Corp
Email: sebastien.bihorel@cognigencorp.com
Phone: (716) 633-3463 ext. 323

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