这与旧问题有关:How to plot bar plot with Chinese names in input file?
在尝试用户提出的各种方法后,我仍然遇到同样的问题。
我的设置:
> sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
然后我做了:
Sys.setlocale("LC_CTYPE", locale="UTF-8")
Sys.setlocale("LC_ALL", "UTF-8")
mydata = matrix( c( 2:6, c( 2,4,2,6,3 ) ), nrow= 2 )
mylabs = c( "木材", "表", "笔", "垃圾桶", "杯" )
barplot( mydata, beside=T, horiz= "T", names.arg= mylabs, las= 1, col= c( "red", "blue" ) )
我得到的错误是:
Error in axis(if (horiz) 2 else 1, at = at.l, labels = names.arg, lty = axis.lty, :
could not find any X11 fonts
Check that the Font Path is correct.
In addition: Warning messages:
1: In (function (display = "", width, height, pointsize, gamma, bg, :
locale not supported by Xlib: some X ops will operate in C locale
2: In (function (display = "", width, height, pointsize, gamma, bg, :
X cannot set locale modifiers
我正在使用OS X Yosemite 10.10.5。
uname -a
Darwin mxmac.local 14.5.0 Darwin Kernel Version 14.5.0:Fri Feb 17 10:33:20 PST 2017; root:xnu-2782.50.9.1.1~1 / RELEASE_X86_64 x86_64
也尝试了“enc2utf8”,但也遇到了同样的错误。