[R] How to plot an expression-label with variable text

David Winsemius dwinsemius at comcast.net
Fri Aug 27 20:40:38 CEST 2010


On Aug 27, 2010, at 2:19 PM, Dieter Menne wrote:

> Disclaimer: I have read plotmath, but maybe it's too late today:
>
> How do I get the two labels to be the same:
>
> plot.new()
> lab =expression(paste("Estimated ", t[50]," from tgv"))
> text(0.5,0.5,lab)
> # Should look the same as above. I could not get the substitute right:
> what = "tgv"
> lab =expression(paste("Estimated ", t[50]," from ",what))
> text(0.5,0.2,lab)

The problem with that method (I think) is that expression protects its  
arguments to some extent. The help page wording is that it is  
"special" and does not evaluate its arguments although you seem to  
have gotten the paste() function evaluated. Try:

plot.new()
lab <- expression(paste("Estimated ", t[50]," from tgv"))
text(0.5,0.5,lab)
# Should look the same as above. I could not get the substitute right:
what <- "tgv" ; expr <- paste("Estimated t[50] from ", what)
lab <- as.expression(expr)  # expression() does not satisfy
text(0.5,0.2,lab)

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list