[R] Plotting the ASCII character set.
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Sun Jul 4 13:15:06 CEST 2021
On 03/07/2021 9:59 p.m., Rolf Turner wrote:
... deletia ...
> Also note that there is a bit of difference between the results of using
> Encoding() and the results of using iconv(). E.g. if I do
>
> a <- "\x80"
> b <- iconv(a,"latin1","UTF-8")
> Encoding(a) <- "latin1"
>
> then when I type "a" I get the Euro symbol "€", but when I type "b"
> I get the string "\u0080"
>
> But that doesn't really matter. More problematic is the fact that if I
> do either
>
> plot(0,0,type="n",xlim=c(0,1),ylim=c(0,1),ann=FALSE,axes=FALSE)
> text(0.5,0.5,labels=a,cex=6)
> or
>
> plot(0,0,type="n",xlim=c(0,1),ylim=c(0,1),ann=FALSE,axes=FALSE)
> text(0.5,0.5,labels=b,cex=6)
>
> then I get wee rectangle with 0 0 8 0 arranged in a 2 x 2 array inside.
> (Setting cex=6 makes it easier for my ageing eyes to see what the
> digits are.)
>
> Is there any way that I can get the Euro symbol to display correctly in
> such a graphic?
The problem with the Euro symbol is that it was invented after the first
8 bit encodings, so it was stuck in later. If you want it, this seems
helpful:
From https://web.stanford.edu/~laurik/fsmbook/faq/utf8.html:
"The proper Unicode code point for € [this may or may not display
correctly as the Euro sign in your browser] is decimal 8364 (0x20AC). In
Windows CP1252 € has the code 128 (0x80); in ISO-8859-15 (also known as
Latin-9) the € code is 164 (0xA4); in Macintosh Roman it is 219 (0xDB)."
So a fairly portable way to display it would be "\u20ac". That works in
a plot on my Mac; on other graphics devices it depends on whether the
glyph is defined, but I'd expect it is fairly widespread.
The "\x80" character varies across 8 bit encodings. In many of them
it's a non-printable character, but not on Windows.
Duncan Murdoch
More information about the R-help
mailing list