[R] combining grid.text, expression and variables
Sebastien Bihorel
sebastien.bihorel at cognigencorp.com
Wed Sep 2 19:20:40 CEST 2009
Hi Baptiste,
Thank for the help. One thing though that I found while transposing your
syntax to my problem: lab must be of class expression for your syntax to
work. For instance, if one replaces the second elements of the lab
variables by a simple integer, lab is not more of class expression, and
grid.text just displays strings of character.
An easy way to bullet proof the code: use as.expression when building lab
Thanks
baptiste auguie wrote:
> Hi,
>
> Try this,
>
>
> library(grid)
>
> value <- c(0.1)
>
> lab <- c("test",
> expression(bquote(paste(.(value[1]*100), " and percentiles1",
> sep=""))),
> bquote(expression(.(value[1]*100)*" and percentiles2")),
> bquote(paste(.(value[1]*100), " and percentiles3", sep="")) )
>
>
> grid.newpage()
> grid.text(eval(lab[1]), x=0.5, y=unit(1,"npc")-unit(1,"lines"))
> grid.text(eval(lab[2]), x=0.5, y=unit(1,"npc")-unit(2,"lines"))
> grid.text(eval(lab[3]), x=0.5, y=unit(1,"npc")-unit(3,"lines"))
> grid.text(lab[4], x=0.5, y=unit(1,"npc")-unit(4,"lines"))
>
> My preference goes for the last one.
>
> HTH,
>
> baptiste
>
> 2009/9/2 Sebastien Bihorel <sebastien.bihorel at cognigencorp.com
> <mailto:sebastien.bihorel at cognigencorp.com>>
>
> 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"))
> }
>
> ______________________________________________
> R-help at r-project.org <mailto:R-help at r-project.org> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
> --
> _____________________________
>
> Baptiste Auguié
>
> School of Physics
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
>
> http://newton.ex.ac.uk/research/emag
> ______________________________
>
More information about the R-help
mailing list