[R] combining grid.text, expression and variables

Sebastien Bihorel sebastien.bihorel at cognigencorp.com
Wed Sep 2 18:21:02 CEST 2009


Dear R-users,

I am trying to use the grid.text and expression functions to display 
several character strings and plotmath text on a viewport. Some strings 
can include a variable portion (PI.limits in the following example), 
which I thought could be implemented by combining the bquote and the 
expression functions. Unfortunately, my expressions do not seem to be 
evaluated. I would greatly appreciate if somebody could tell me where my 
mistake(s) is(are).

Thank you in advance


###### 8< #######

library(grid)

PI.limits <- c(0.1,0.9)
 
vp.ref <- c("raw data","median","median",
                 bquote(expression(paste(.(PI.limits[1]*100), " and ",
                                         .(PI.limits[2]*100)^th," 
percentiles", sep=""))),
                 bquote(expression(paste(95^th,"confidence interval on 
percentiles", sep=" "))),
                 bquote(expression(paste(95^th,"confidence interval on 
percentiles", sep=" ")))
                 )


grid.newpage()

for (i in c(1,3,4,5,6)) {
  grid.text(eval(vp.ref[i]), x=0.5, y=unit(1,"npc")-unit(i,"lines"))
}




More information about the R-help mailing list