[R] Plot symbols: How to plot (and save) a graphic with symbols originating from a table

Gabor Grothendieck ggrothendieck at gmail.com
Sat Jan 1 23:08:35 CET 2011


On Sat, Jan 1, 2011 at 3:00 PM, Victor F Seabra <vseabra at uol.com.br> wrote:
>
>   Dear all,
>   Please, I have a doubt regarding symbols plotting
>   when the data originates from a table
>   (i.e. is not manually fed into the "text" function)
>   Please, see below:
>   I have a tab delimited file called table1.txt with 4 columns.
>   (I wasn't sure on how to attach the table to this post, so I included the
>   data below)
>   ypos animal var1 var2
>   5 cat gina <= lady gina \u2264 lady
>   7 dog bill >= tony bill \u2265 tony
>   9 fish dude <= bro dude \u2264 bro
>   # I load in the data:
>   table1<-read.table("table1.txt", header=TRUE, sep="\t")
>   #
>   # If I take a look at the table
>   table1
>   # I realize that \u2264 was replaced by \\u2264
>   #
>   # So, when I plot the data
>   plot(1:1,col="white",xlim=c(1,10),ylim=c(1,10),ylab="",axes=FALSE,xlab="")
>   text(y=table1$ypos,x=2,table1$animal)
>   text(y=table1$ypos,x=4,table1$var1)
>   text(y=table1$ypos,x=8,table1$var2)
>   #
>   # Instead of "<=" or ">=", the text string "\u2265" is plotted
>   # This first problem can be fixed by manually erasing the extra "\" on var2
>   fix(table1)
>   #
>   # However, while saving the graph to a ps file, the "<=" sign is replaced by
>   "..."
>   postscript("graph1.ps", width = 22, height =
>   11.5,pointsize=24,paper="special",bg="transparent")
>   plot(1:1,col="white",xlim=c(1,10),ylim=c(1,10),ylab="",axes=FALSE,xlab="")
>   text(y=table1$ypos,x=2,table1$animal)
>   text(y=table1$ypos,x=4,table1$var1)
>   text(y=table1$ypos,x=8,table1$var2)
>   dev.off()
>   #
>   #
>   # A solution would be to plot "<" or ">" instead of "<=" and ">=" signs
>   # and then plot an hifen under the "<" or the ">" sign.
>   # This approach fixes both problems, but is hard to do and
>   # very difficult to automate
>   #
>   #Please, does anyone know a better way?
>   #thanks in advance
>   #
>   #Victor Faria Seabra, MD
>   #vseabra@ uol.com.br

Try this which illustrates the idea without all the distraction of the
inessential elements:

   plot(0, main = eval(parse(text = sprintf("'%s'", "a\\u2264b"))))


That is, within the context of your post the last line would be replaced with:

   text(y=table1$ypos, x = 8, eval(parse(text = sprintf("'%s'", table1$var2))))


Whether this works may depend on the OS and device that you use -- it
does work on my Windows Vista system.


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list