2016-09-03 100 views
0

我剛剛安裝了Ubuntu 14.04 web服務器並將語言環境更改爲zh_CN.UTF-8。但ggplot2不能在標籤中顯示中文字符。在ggplot2中顯示中文字符

library(ggplot2) 
x_lab <- enc2utf8('中國') 
p <- ggplot(cars) + geom_point(aes(speed, dist)) + 
xlab(x_lab) 
png('a.png') 
print(p) 
dev.off() 

結果是這樣的

enter image description here

任何想法來解決這個問題?

PS:我有另一個具有相同語言環境的Web服務器,但對我來說工作正常。

這是我sessionInfo

> sessionInfo() 
R version 3.3.1 (2016-06-21) 
Platform: x86_64-pc-linux-gnu (64-bit) 
Running under: Ubuntu 14.04.5 LTS 

locale: 
[1] LC_CTYPE=zh_CN.UTF-8  LC_NUMERIC=C 
[3] LC_TIME=zh_CN.UTF-8  LC_COLLATE=zh_CN.UTF-8 
[5] LC_MONETARY=zh_CN.UTF-8 LC_MESSAGES=zh_CN.UTF-8 
[7] LC_PAPER=zh_CN.UTF-8  LC_NAME=C 
[9] LC_ADDRESS=C    LC_TELEPHONE=C 
[11] LC_MEASUREMENT=zh_CN.UTF-8 LC_IDENTIFICATION=C 

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

other attached packages: 
[1] ggplot2_2.1.0 

loaded via a namespace (and not attached): 
[1] colorspace_1.2-6 scales_0.4.0  plyr_1.8.4  gtable_0.2.0 
[5] Rcpp_0.12.6  grid_3.3.1  munsell_0.4.3 

回答

0

圖出這個問題。我需要在新服務器上安裝的字體中國,然後roboot:

sudo apt-get install fonts-wqy-zenhei 
sudo apt-get install fonts-arphic-bkai00mp fonts-arphic-bsmi00lp fonts-arphic-gbsn00lp fonts-arphic-gkai00mp fonts-arphic-ukai fonts-arphic-uming fonts-cns11643-kai fonts-cns11643-sung fonts-cwtex-fs fonts-cwtex-heib fonts-cwtex-kai fonts-cwtex-ming fonts-cwtex-yen 

看到這個頁面:https://askubuntu.com/questions/490829/how-can-i-install-chinese-fonts-on-kubuntu-14-04