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

David Winsemius dwinsemius at comcast.net
Fri Aug 27 22:32:41 CEST 2010


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

>
> Thanks to both of you. I noted that my example was over-simplified.  
> Looks
> like I need to correct the environment when nested in a function,  
> but I have
> to catch the last bus now.
>
> Dieter
>
>
> plotExp = function(what) {
>  plot.new()
>  lab =expression(paste("Estimated ", t[50]," from tgv"))
>  text(0.5,0.5,lab)
>  # Should look the same as above. Looks like I need a substitute....
>  lab =bquote(paste("Estimated ", t[50]," from ",.(what))) ##<<need
> environment
>  text(0.5,0.2,lab)
> }
> plotExp(what)
>

Hope you caught the bus. Doesn't appear that an environment is needed  
if you don't add the paste() operation:

what= "tgv"
plotExp <- function(what) {
  plot.new()
  lab =expression(paste("Estimated ", t[50]," from tgv"))
  text(0.5,0.5,lab)
   lab =bquote(Estimated~t[50]~ from ~.(what) ) ;  text(0.5,0.2,lab)
    }
plot(what)

Furthermore I could not see from what infirmities the first version  
suffered.


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list