Re: [R] How to draw a per mille symbol?

From: Paul Murrell <p.murrell_at_auckland.ac.nz>
Date: Wed 20 Sep 2006 - 03:28:51 GMT

Hi

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)

grid.prompt(TRUE)
digits <- c(0:9, letters[1:6])
for (i in c("00", "01", "02", "03", "1e", "20", "21", "22")) {
     grid.newpage()
     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")))
             eval(parse(text=paste('grid.text("\\u',
                          i, digits[k], digits[j], '")', sep="")))
             popViewport()
         }
     }

}

> 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")
dev.off()

Paul

> 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
Auckland
New Zealand
64 9 3737599 x85392
paul@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Wed Sep 20 13:31:52 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 20 Sep 2006 - 11:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.