[R] adding text in (pair) panels (splom)

Patrick Giraudoux patrick.giraudoux at univ-fcomte.fr
Sat Apr 10 05:13:39 CEST 2004


OK Paul and Kjetil

I understand that grid.text is part of the library grid. I have tried with Paul's arguments. It works perfectly well.

Thanks a lot both,

Patrick


----- Original Message ----- 
From: "Paul Murrell" <p.murrell at auckland.ac.nz>
To: "Patrick Giraudoux" <patrick.giraudoux at univ-fcomte.fr>
Cc: "r-help" <r-help at stat.math.ethz.ch>
Sent: Saturday, April 10, 2004 4:39 AM
Subject: Re: [R] adding text in (pair) panels (splom)


> Hi
>
>
> Patrick Giraudoux wrote:
> > Hi,
> >
> > I would like to add text in each panel got from the following:
> >
> > splom(~Cs5bis,
> > panel=function(x,y,...){
> > panel.xyplot(x,y,...)
> > panel.abline(lm(y~x),...)
> > })
> >
> > This could be a correlation coefficient or the statistical significance of the correlation or both, or a star if p < 0.05,
etc...
> > The function text() is useless (probably because I cannot pass appropriates coordinates in each panel). Googling the R-archives,
I
> > have found only one hint of Andy Liaw relating a rather complex (to me) script within a home-made panel.myfitline() function.
> >
> > Is there a simple way to add text in panels created eg with:
> >
> > panel=function(x,y,...){
> > panel.xyplot(x,y,...)
> > panel.abline(lm(y~x),...)
> > })
>
>
> text() is useless because splom is a lattice function and lattice is
> based on grid.  To add text in a panel you could use lattice's ltext(),
> but I think the best way would be to use grid.text() as below.  This
> example draws the correlation coefficient 1mm in from the top-left
> corner of the panel.
>
>
> panel=function(x,y,...){
>   panel.xyplot(x,y,...)
>   panel.abline(lm(y~x),...)
>            grid.text(round(cor(x, y), 2),
>              x=unit(1, "mm"), y=unit(1, "npc") - unit(1, "mm"),
>              just=c("left", "top"))
> })
>
> Does that do what you want?
>
> Paul
> -- 
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> paul at stat.auckland.ac.nz
> http://www.stat.auckland.ac.nz/~paul/




More information about the R-help mailing list