[R] automatic font selection, please help

From: Jinsong Zhao <jszhao_at_yeah.net>
Date: Thu, 21 Apr 2011 11:22:29 +0800

Hi there,

With the helps from this list, I can set specific CJK fonts for character string using text() function. for example:

song <- CIDFont("SimSun", "GBK-EUC-H", "GBK", "")

postscriptFonts(song = song)

postscript("test.ps", height = 7, width =7, family = "Times", fonts = c("song"), horizontal = FALSE, onefile = FALSE, paper = "special")

plot(1:10, xlab = "")
mtext("\u4F60\u597D", family="song", font = 1, side = 1, line = 2)

text(1,1, "\u4F60\u597D", family="song", font = 1)
text(3,1, "\u4F60\u597D", family="song", font = 2)
text(5,1, "\u4F60\u597D", family="song", font = 3)
text(7,1, "\u4F60\u597D", family="song", font = 4)


Now, I hope to change the xlab to "\u4F60\u597D (Hello)", than, I using the following code:

mtext("\u4F60\u597D (Hello)", family="song", font = 1, side=1, line=2)

Now, the typeface of " (Hello)" is "song", however, I hope it is "Times", which looks better than "song".

If using windows() as graphic device, the \u4F60\u597D can be displayed correctly in "song" (the default font, but I don't know how to change it), and " (Hello)" in "Times" with par(family = "serif").

The question is: how to set R for automatic font selection, i.e., for latin or ascii characters using "Times", and Chinese characters using "song"?

Any suggestions or comments will be really appreciated. Thanks in advance.


 > sessionInfo()
R version 2.11.1 (2010-05-31)

[1] LC_COLLATE=Chinese_People's Republic of China.936
[2] LC_CTYPE=Chinese_People's Republic of China.936
[3] LC_MONETARY=Chinese_People's Republic of China.936
[5] LC_TIME=Chinese_People's Republic of China.936

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] tools_2.11.1

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. Received on Thu 21 Apr 2011 - 03:26:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 21 Apr 2011 - 05:30:31 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.

list of date sections of archive