[R] How to handle Chinese character in R plot?
jszhao at yeah.net
Mon Oct 15 11:25:47 CEST 2012
On 2012-10-15 9:40, Manish Gupta wrote:
> I just noticed chinese characters are not printed by using this. Some other
> characters gets printed on axis as shown below for the sugested solution.
> x <- read.csv(textConnection("名称,类,学生
> 杯,6,3"), header = TRUE)
> rownames(x) <- x[,1]
> x <- x[,-1]
> barplot(t(x), horiz = TRUE, beside = TRUE, legend.text = TRUE, xlab="名称类学生")
I have test this code in a FreeBSD. The locale of the OS is "C".
After starting R, I use `Sys.setlocale(category = "LC_ALL", locale =
"zh_CN.UTF-8")' to set the internal locale of R to "zh_CN.UTF-8".
I save the above command in a file with encoding of UTF-8. And in R, I
use `source("a.txt", encoding="UTF-8")'. I can get a figure, with
correct characters (in Chinese) in all positions except that in legend
(I don't know why?).
More information about the R-help