[R] Expression in panel.text

Deepayan Sarkar deepayan at stat.wisc.edu
Fri Apr 22 19:03:50 CEST 2005


On Friday 22 April 2005 10:12, David Orme wrote:
> Hi,
>
> I've got a lattice xyplot and I want to superimpose correlation
> coefficients and p values on each panel. I've been trying to get this
> to work using something of the form:
>
> x <- rnorm(400)
> y <- rnorm(400)
> a <- gl(4, 100)
>
> xyplot(y~x | a,
>   panel=function(x,y, ...){
>    panel.xyplot(x,y, ...)
>          curr.cor <- cor.test(x,y)
>          crho <- round(curr.cor$estimate,2)
>          cpv <- format.pval(curr.cor$p.value, eps = 0.01, digits=2)
>          exprrho <- substitute(rho == crho, list(crho=crho))
>          exprpv <- substitute(italic(p) == cpv, list(cpv=cpv))
>          panel.text(-2, 2, label=exprrho)
>               panel.text(2, 2, label=exprpv)
>          })
>
> The two expressions (expprho and exprpv) plot as expected on a normal
> text() call  but in the panels, all that appears at the coordinates is
> "==". This is the first element in exprrho; other than that,  I can't
> figure out what is going wrong.
>
> Any suggestions?

I believe this came up a few days back. 

> exprrho <- substitute(rho == crho, list(crho=.12))
> is.expression(exprrho)
[1] FALSE

i.e., the label you are using is not an expression. The 'panel.text' you have 
didn't take this possibility into account (unlike 'text').

The good news is that this has been fixed in R 2.1.0.

Deepayan




More information about the R-help mailing list