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

Greg Snow 538280 at gmail.com
Thu Jun 7 19:23:47 CEST 2012


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



More information about the R-help mailing list