Victor F Seabra
2011-Jan-01 19:15 UTC
[R] Plot symbols: How to plot (and save) a graphic symbols originating from a table
Dear all, Please, I have a doubt regarding symbol plotting with data originating from a table. Please, see below: I have a tab delimited file called table1.txt with 4 columns: 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 then load in the data to R: table1<-read.table("table1.txt", header=TRUE, sep="\t") #if I take a look at the table I realize that \u2264 was replaced by \\u2264 table1 #So, if i try to plot the data #instead of greater/equal or lesser/equal I get #a text string plotted "\u2265" 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) #this can be fixed if I manually erase the extra "\" on var2 fix(table1) 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) #However if I save the graph to a ps file, it shows the "<=" sign as "..." postscript("teste3.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() #My solution was to plot "<" or ">" instead of "<=" and ">=" # and then plot an hifen under the "<" or the ">" sign. # This worked to fix both problems, but is hard to do and # impossible to automate (or at least very difficult) #Please, does anyone know a better approach? #thanks in advance Victor Faria Seabra, MD vseabra at uol.com.br
Victor F Seabra
2011-Jan-01 19:40 UTC
[R] Plot symbols: How to plot (and save) a graphic symbols originating from a table
sorry, I guess the table was a little confusing, I've quoted each cell to facilitate reading and attached a copy of the database file. 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" By the way, I'm running R on windows and didn't try any of this on Linux. thanks in advance, Victor ? ? Victor Faria Seabra Email: vseabra at uol.com.br _________________________________________________________________ Em 01/01/2011 17:15, Victor F Seabra < vseabra at uol.com.br > escreveu: Dear all, Please, I have a doubt regarding symbol plotting with data originating from a table. Please, see below: I have a tab delimited file called table1.txt with 4 columns: 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 then load in the data to R: table1<-read.table("table1.txt", header=TRUE, sep="\t") #if I take a look at the table I realize that \u2264 was replaced by \\u2264 table1 #So, if i try to plot the data #instead of greater/equal or lesser/equal I get #a text string plotted "\u2265" 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) #this can be fixed if I manually erase the extra "\" on var2 fix(table1) 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) #However if I save the graph to a ps file, it shows the "<=" sign as "..." postscript("teste3.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() #My solution was to plot "<" or ">" instead of "<=" and ">=" # and then plot an hifen under the "<" or the ">" sign. # This worked to fix both problems, but is hard to do and # impossible to automate (or at least very difficult) #Please, does anyone know a better approach? #thanks in advance Victor Faria Seabra, MD vseabra at uol.com.br ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: table1.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110101/ee5a922c/attachment.txt>
David Winsemius
2011-Jan-01 19:59 UTC
[R] Plot symbols: How to plot (and save) a graphic symbols originating from a table
On Jan 1, 2011, at 2:15 PM, Victor F Seabra wrote:> Dear all, > > Please, I have a doubt regarding symbol plotting > with data originating from a table.I would say it has very little to do with the data structure and everything to do with the encodings, font conventions of console output, and the defaults for graphical devices. (I'm using a Mac in an English locale, and you have not provided any of the requested information about your setup.)> > Please, see below: > > I have a tab delimited file called table1.txt with 4 columns: > > 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 then load in the data to R: > table1<-read.table("table1.txt", header=TRUE, sep="\t") > > #if I take a look at the table I realize that \u2264 was replaced by > \\u2264 > table1 >No. You are more likely seeing how R presents what it did with \u2264 with its default method for printing to the console. I see: > table1 ypos animal var1 var2 1 5 cat gina <= lady gina ? lady 2 7 dog bill >= tony bill ? tony 3 9 fish dude <= bro dude ? bro Subject, of course, to how emailers handle the \u2264 character. > str(table1) 'data.frame': 3 obs. of 4 variables: $ ypos : num 5 7 9 $ animal: Factor w/ 3 levels "cat","dog","fish": 1 2 3 $ var1 : Factor w/ 3 levels "bill >= tony",..: 3 1 2 $ var2 : Factor w/ 3 levels "bill ? tony",..: 3 1 2> #So, if i try to plot the data > #instead of greater/equal or lesser/equal I get > #a text string plotted "\u2265" > 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) > > #this can be fixed if I manually erase the extra "\" on var2 > fix(table1)I'm confused. You are starting with a factor variable whose levels have some higher order numbers in the character vector, and then you didn't assign the results of the fix() operation to an R object. Why should that do _anything_?> 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) > > #However if I save the graph to a ps file, it shows the "<=" sign as > "..." > postscript("teste3.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() >That must be the glyph for that number in the default font for your pdf device (as it is for mine once I change the width settings so it can be seen after conversion to pdf.) ?Encoding # might be a useful place to start, followed by... ?Devices ?ps.options> > #My solution was to plot "<" or ">" instead of "<=" and ">=" > # and then plot an hifen under the "<" or the ">" sign. > # This worked to fix both problems, but is hard to do and > # impossible to automate (or at least very difficult) > > #Please, does anyone know a better approach?To accomplish what end? You have not described what you are trying to actually do. Is this text supposed to be plotted inside the plotting area or are you going to be using it as axis labels? There is a variety of approaches (especially the plotmath expression option) that can be used depending on the ultimate objective. ?plotmath Compare: plot(NULL, xlim=c(0,1), ylim=c(0,1)) text(0.5,0.5, as.expression(as.character(table1$var2[1])) ) text(0.5,0.6, label=expression(gina <= lady) )> #thanks in advance > > Victor Faria Seabra, MD > vseabra at uol.com.br-- David Winsemius, MD West Hartford, CT
Victor F Seabra
2011-Jan-01 20:00 UTC
[R] Plot symbols: How to plot (and save) a graphic with symbols originating from a table
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