[R] non ascill characters in plots. no alternative but plotmath?

David Winsemius dwinsemius at comcast.net
Thu Jun 7 06:06:25 CEST 2012


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. Johnson


David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list