Paul Johnson
2012-Jun-06 23:23 UTC
[R] non ascill characters in plots. no alternative but plotmath?
A student entered some data with text characters like epsilon and alpha. On her Windows system, the Greek letters did not display properly in a plot. There were some ordinary ASCII instead. I asked her to send me the code so I could test. For me, the plot looks ok on the screen. Format1 <- c(320,500,700,1000,500,320,700,500,320) Format2 <- c(800,1000,1150,1400,1500,1650,1800,2300,2500) Vowel <- c("u","o", "?", "a","?", "y", "?", "e","i") V1 <- data.frame(Format1,Format2,Vowel) plot(Format1 ~ Format2, data = V1, type="n") text(V1$Format2, V1$Format1, labels=V1$Vowel) On my Debian linux system, the plot shows the Greek letters just fine in the screen device. However, I turned on a pdf device to run the same code and see signs of trouble.> text(V1$Format2, V1$Format1, labels=V1$Vowel)Warning messages: 1: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> 2: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b1> 3: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : font metrics unknown for Unicode character U+03b1 4: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> 5: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b1> 6: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> 7: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b5> 8: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : font metrics unknown for Unicode character U+03b5 9: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> 10: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b5> The alpha and epsilon characters don't appear in the pdf. I don't know the proper terminology to describe the situation, thus I don't know where to start reading. Until very recently, I didn't even know it was possible to directly enter these characters in Emacs, but I've learned that part. I understand you might answer "use plotmath", if if that's the only workable thing, I will teach her how. But that's a little bit of an up hill climb (from where we are now standing). It will be a lot more work for me to teach about expressions and whatnot, so if there is a direct route from a column of non ASCII characters to a plot that has those characters in it, I'd be glad to know. pj -- Paul E. Johnson Professor, Political Science ? ?Assoc. Director 1541 Lilac Lane, Room 504 ? ? Center for Research Methods University of Kansas ? ? ? ? ? ? ? University of Kansas http://pj.freefaculty.org ? ? ? ? ? ?http://quant.ku.edu
David Winsemius
2012-Jun-07 04:06 UTC
[R] non ascill characters in plots. no alternative but plotmath?
On Jun 6, 2012, at 7:23 PM, Paul Johnson wrote:> A student entered some data with text characters like epsilon and > alpha. On her Windows system, the Greek letters did not display > properly in a plot. There were some ordinary ASCII instead. > > I asked her to send me the code so I could test. For me, the plot > looks ok on the screen. > > Format1 <- c(320,500,700,1000,500,320,700,500,320) > Format2 <- c(800,1000,1150,1400,1500,1650,1800,2300,2500) > Vowel <- c("u","o", "?", "a","?", "y", "?", "e","i") > V1 <- data.frame(Format1,Format2,Vowel) > plot(Format1 ~ Format2, data = V1, type="n") > text(V1$Format2, V1$Format1, labels=V1$Vowel)> > On my Debian linux system, the plot shows the Greek letters just fine > in the screen device.Also on a Mac.> > However, I turned on a pdf device to run the same code and see signs > of trouble.Try the code on ?points (as suggested on the ?plotmath page: > pdf("font5.pdf") > TestChars <- function(sign=1, font=1, ...) + { + if(font == 5) { sign <- 1; r <- c(32:126, 160:254) + } else if (l10n_info()$MBCS) r <- 32:126 else r <- 32:255 + if (sign == -1) r <- c(32:126, 160:255) + par(pty="s") + plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="", + xaxs="i", yaxs="i") + grid(17, 17, lty=1) + for(i in r) try(points(i%%16, i%/%16, pch=sign*i, font=font,...)) + } > > TestChars(font=5) Warning messages: 1: In plot.xy(xy.coords(x, y), type = type, ...) : font width unknown for character 0xf0 2: In plot.xy(xy.coords(x, y), type = type, ...) : font metrics unknown for character 0xf0 > dev.off() Despite the single warning, you do get a full set of "greeks". (When I have done this in the past I have added decimal annotations to the plot and taped it to my computer.) But using plotmath seems simple to me, so I generally use it for greeks and only use the type=5 mechanism for special non-plotmath characters. If you set font=5 inside your text() call, some of your greeks will appear but you may get some surprises. -- David.> >> text(V1$Format2, V1$Format1, labels=V1$Vowel) > Warning messages: > 1: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> > 2: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b1> > 3: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > font metrics unknown for Unicode character U+03b1 > 4: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> > 5: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b1> > 6: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> > 7: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b5> > 8: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > font metrics unknown for Unicode character U+03b5 > 9: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> > 10: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b5> > > The alpha and epsilon characters don't appear in the pdf. I don't > know the proper terminology to describe the situation, thus I don't > know where to start reading. Until very recently, I didn't even know > it was possible to directly enter these characters in Emacs, but I've > learned that part. > > I understand you might answer "use plotmath", if if that's the only > workable thing, I will teach her how. But that's a little bit of an up > hill climb (from where we are now standing). It will be a lot more > work for me to teach about expressions and whatnot, so if there is a > direct route from a column of non ASCII characters to a plot that has > those characters in it, I'd be glad to know. > > pj > > -- > Paul E. JohnsonDavid Winsemius, MD Heritage Laboratories West Hartford, CT
Greg Snow
2012-Jun-07 17:23 UTC
[R] non ascill characters in plots. no alternative but plotmath?
I think the problem is with fonts and encodings. The pdf device is using a different font and/or encoding than the screen device and so the non-ascii characters are looking different. If you can convince the pdf driver to use the same font and encoding then the symbols/characters in the plot should look the same, but my personal experience (not knowing font and encoding details very well) is that using plotmath or David's suggestions would probably be easier (and more useful in the long run). A couple of other options which are probably more work than plotmath in general (but may be better for some specific cases) are: Use the tikz device and then process using LaTeX to get the pdf file (this way you have the full power of LaTeX and fonts match text). Make bitmap images of the symbols you want to use, convert them to rasters and use rasterImage to add them to the plot. Find points that when connected by lines will draw your image, then use the my.symbols function (TeachingDemos package) to add them to the plot. On Wed, Jun 6, 2012 at 5:23 PM, Paul Johnson <pauljohn32 at gmail.com> wrote:> A student entered some data with text characters like epsilon and > alpha. ? On her Windows system, the Greek letters did not display > properly in a plot. ?There were some ordinary ASCII instead. > > I asked her to send me the code so I could test. For me, the plot > looks ok on the screen. > > Format1 <- c(320,500,700,1000,500,320,700,500,320) > Format2 <- c(800,1000,1150,1400,1500,1650,1800,2300,2500) > Vowel <- c("u","o", "?", "a","?", "y", "?", "e","i") > V1 <- data.frame(Format1,Format2,Vowel) > plot(Format1 ~ Format2, data = V1, type="n") > text(V1$Format2, V1$Format1, labels=V1$Vowel) > > On my Debian linux system, the plot shows the Greek letters just fine > in the screen device. > > However, I turned on a pdf device to run the same ?code and see signs > of trouble. > >> text(V1$Format2, V1$Format1, labels=V1$Vowel) > Warning messages: > 1: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > ?conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> > 2: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > ?conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b1> > 3: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > ?font metrics unknown for Unicode character U+03b1 > 4: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > ?conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> > 5: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > ?conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b1> > 6: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > ?conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> > 7: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > ?conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b5> > 8: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > ?font metrics unknown for Unicode character U+03b5 > 9: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > ?conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce> > 10: In text.default(V1$Format2, V1$Format1, labels = V1$Vowel) : > ?conversion failure on '?' in 'mbcsToSbcs': dot substituted for <b5> > > The alpha and epsilon characters don't appear in the pdf. ? I don't > know the proper terminology to describe the situation, thus I don't > know where to start reading. Until very recently, I didn't even know > it was possible to directly enter these characters in Emacs, but I've > learned that part. > > I understand you might answer "use plotmath", if if that's the only > workable thing, I will teach her how. But that's a little bit of an up > hill climb (from where we are now standing). It will be a lot more > work for me to teach about expressions and whatnot, so if there is a > direct route from a column of non ASCII characters to a plot that has > those characters in it, I'd be glad to know. > > pj > > -- > Paul E. Johnson > Professor, Political Science ? ?Assoc. Director > 1541 Lilac Lane, Room 504 ? ? Center for Research Methods > University of Kansas ? ? ? ? ? ? ? University of Kansas > http://pj.freefaculty.org ? ? ? ? ? ?http://quant.ku.edu > > ______________________________________________ > 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.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com