[R] How to draw a per mille symbol?

Paul Murrell p.murrell at auckland.ac.nz
Wed Sep 20 05:28:51 CEST 2006


Gavin Simpson wrote:
> Dear list,
> Following advice posted to this list a while back by Prof Ripley [1], I
> have been trying to draw a per mille character [2] in an axis label.
> This should give the correct character:
> plot(1:10, ylab = "\u2030")
> but all I get is '"S'. I'm running linux (FC5) and have fonts installed
> that have the correct character (viewed in the Gnome character map at
> least).

I get the same thing (and using xfd I see the per mille character in the 
font I'm using).  I'm afraid I'm not sure why this is happening;  I can 
get a number of other "unusual" characters to work (e.g., \u20ac), but 
there appear to be some characters that do not draw correctly.  I used 
the following code to explore the default Helvetica font I've got and I 
can't see a rational pattern in the misbehaviour.

x11(width=5, height=5)
digits <- c(0:9, letters[1:6])
for (i in c("00", "01", "02", "03", "1e", "20", "21", "22")) {
     for (j in 1:16) {
         for (k in 1:16) {
             pushViewport(viewport(x=j/16, y=1-k/16,
                                   width=1/16, height=1/16,
                                   just=c("right", "bottom")))
                          i, digits[k], digits[j], '")', sep="")))

> I have also tried plotting to a pdf device with a font family that the
> character map tool shows I have a per mille glyph for, e.g.:
> pdf("~/tmp/test_per_mille.pdf", paper = "a4", family = "URWBookman")
> plot(1:10, ylab = "\u2030")
> dev.off()
> But all I get here is a period or a dot-like symbol.

This is an encoding problem I think.  For producing PDF output, the 
character string gets converted to a single-byte encoding.   If your 
default locale is ISOLatin1 like mine then you won't see the per mille 
because that character (called perthousand in the Adobe afm's) is not in 
the ISOLatin1 encoding.  If you explicitly use an encoding that does 
include perthousand (like WinAnsi) then the conversion to single-byte 
encoding works.  For example, this works (for me at least) ...

pdf("WinAnsi_per_mille.pdf", encoding="WinAnsi")
plot(1:10, ylab = "\u2030")


> I've tried this in R 2.4.0 alpha [4] and R 2.5.0 to be [4] as my
> self-compiled R 2.3.1-patched dies when plotting Unicode characters
> (fixed in 2.4.0 alpha and above [3])
> Can anyone point me in the right direction to get this working?
> TIA,
> G
> [1] http://finzi.psych.upenn.edu/R/Rhelp02a/archive/48709.html
> [2] like a "%" but with 2 circles at the bottom not one, see
> http://en.wikipedia.org/wiki/Permille
> [3] see thread at http://article.gmane.org/gmane.comp.lang.r.devel/9704
> [4] R version 2.4.0 alpha (2006-09-19 r39410)
> [5] R version 2.5.0 Under development (unstable) (2006-09-19 r39410)

Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz

More information about the R-help mailing list