Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Theme() doesn't work for ggplot2 Unicode display

Tags:

r

unicode

ggplot2

ggplot(data = d1.6, aes(x = index, y = value, shape = variable)) +
  geom_point() +
  labs(x = "index", y = "tensile strength") +
  scale_shape_manual(name = "temperature", values = c(19, 5), labels = c("20°C", "40°C")) +
  theme(text = element_text(family = "Arial Unicode MS"))

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.13.4 (unknown)

locale:
[1] C

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

other attached packages:
[1] MASS_7.3-45    reshape2_1.4.3 ggplot2_3.0.0 

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18     rstudioapi_0.7   bindr_0.1.1      magrittr_1.5     tidyselect_0.2.4
 [6] munsell_0.5.0    colorspace_1.3-2 R6_2.2.2         rlang_0.2.2      stringr_1.3.1   
[11] plyr_1.8.4       dplyr_0.7.6      tools_3.3.1      grid_3.3.1       gtable_0.2.0    
[16] withr_2.1.2      yaml_2.2.0       lazyeval_0.2.1   assertthat_0.2.0 digest_0.6.16   
[21] tibble_1.4.2     crayon_1.3.4     bindrcpp_0.2.2   purrr_0.2.5      glue_1.3.0      
[26] labeling_0.3     stringi_1.2.4    pillar_1.3.0     scales_1.0.0     pkgconfig_2.0.2 

Specifying a Unicode supportive font does not make Unicode characters display normally. In case you don't want to view the image, the characters (°) are replaced with "..".

enter image description here

like image 952
Eureka Zheng Avatar asked Aug 17 '26 01:08

Eureka Zheng


1 Answers

The problem is that my R locale is "C". By changing it to another option (Chinese):

system("defaults write org.R-project.R force.LANG zh_CN.UTF-8")

And relaunch RConsole, it works perfectly.

like image 95
Eureka Zheng Avatar answered Aug 19 '26 19:08

Eureka Zheng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!