Skip to content

Please, need help with a plot

5 messages · Ben Bolker, David Winsemius, Victor F Seabra +1 more

#
Please, I wonder if someone knows how to add the
   less than or equal to symbol in the plot generated by the code below:
   var1<-c('age <= 3','age <= 7','age <= 10','age <= 11','age <= 20','age <=
   25','age <= 30','age <= 45','age <= 50','age < 55','age >= 55')
   var2<-c(3.8,5.4,3.7,3.8,5.9,6.4,7.2,8.4,10.5,1.3,0.7)
   table1<-data.frame(var1, var2)
   plot(x=table1$var2,y=1:11,xlim=c(0,20),pch=20)
   text(x=table1$var2,y=1:11,table1$var1,pos=4)
   title(x=15,y=5,expression("how  to  substitute  the  < = with the " <=
   "symbol"),font=5)
   Please, note that the data must come from a table (not manually fed in a
   text command)
   I received help yesterday and learned a fix using
   \u2264, eval, parse, and sprintf?  but the symbols generated by this fix are
   not exported to an .EPS file
   Kind regards,

   Victor Faria Seabra, MD
#
Victor F Seabra <vseabra <at> uol.com.br> writes:
This is a little bit more 'magic' than I would like, but seems
to work. Perhaps someone else can suggest a cleaner solution.

ages <- gsub("[^0-9]+","",table1$var1)
rel <- gsub("age\\s*([=<>]+)\\s*[0-9]+","\\1",table1$var1,perl=TRUE)

with(table1,plot(var2,1:11,xlim=c(0,20),pch=20))
invisible(with(table1,
     mapply(function(x,y,a,r) {
       text(x=x,y=y,
            switch(r,
                   `<=`=bquote(age <= .(a)),
                   `<`=bquote(age < .(a)),
                   `>=`=bquote(age >= .(a))),
            pos=4)},
       var2,1:11,ages,rel)))
#
On Jan 2, 2011, at 1:15 PM, Ben Bolker wrote:

            
Here's the best I could come up with but will admit that there were  
many failed attempts before success:

expr.vec <- as.expression(parse(text=table1$var1))
plot(x=table1$var2 ,y=1:11, xlim=c(0,20), pch=20)
text(x=table1$var2, y=1:11, labels=expr.vec, pos=4)
title(x=15, y=5, expression("Yet another way to process strings with  
operators like '<=' )

(The title expression works on my machine, but perhaps not on the OP's  
machine, given differences in encoding that have so far been exhibited.)
David Winsemius, MD
West Hartford, CT
#
although the code somehow didn't work on my Vista / R 2.8,
it did work perfectly on a XP machine / R 2.10

I've been trying to fix this for days,
Thank you very much for your help!


______________________________________________________________________
02/01/2011 19:30, David Winsemius < dwinsemius at comcast.net > wrote:

        
On Jan 2, 2011, at 1:15 PM, Ben Bolker wrote:

            
Here's the best I could come up with but will admit that there were
many failed attempts before success:

expr.vec <- as.expression(parse(text=table1$var1))
plot(x=table1$var2 ,y=1:11, xlim=c(0,20), pch=20)
text(x=table1$var2, y=1:11, labels=expr.vec, pos=4)
title(x=15, y=5, expression("Yet another way to process strings with
operators like '<=' )

(The title expression works on my machine, but perhaps not on the OP's
machine, given differences in encoding that have so far been exhibited.)
David Winsemius, MD
West Hartford, CT
#
On 03.01.2011 14:25, Victor F Seabra wrote:
An when you update both machines to a recent R-2.12.1 you will find how 
much more will work in the end!

Uwe Ligges