[R] how to paste a vector to expression?

David Winsemius dwinsemius at comcast.net
Tue Aug 17 20:19:21 CEST 2010


On Aug 17, 2010, at 11:51 AM, Kay Cichini wrote:

>
> hello,
>
> i need to annotate a plot with an expression and a variable value -  
> like:
>
> plot(1:4)
> dat<-1:2
> text(2:3,2:3,expression(paste(bar(x)==dat)))
>
>
> ... but with the dat values plotted, 1 at x=2,y=2, and 2 at x=3,y=3.

One way ... actually the first success after several earlier failed  
efforts that I thought should have worked :

plot(1:4)
dat<-1:2
text(2:3,2:3,labels=sapply(dat,
        function(x) as.expression(substitute(list(bar("x") == x),  
list(x=x) )) ))

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list