[R] automatic font selection, please help

Jinsong Zhao jszhao at yeah.net
Thu Apr 21 05:22:29 CEST 2011


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)

dev.off()

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.

Regards,
Jinsong



 > sessionInfo()
R version 2.11.1 (2010-05-31)
i386-pc-mingw32

locale:
[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
[4] LC_NUMERIC=C
[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



More information about the R-help mailing list