r - Theme() 不适用于 ggplot2 Unicode 显示

标签 r ggplot2 unicode

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 

指定支持 Unicode 的字体不会使 Unicode 字符正常显示。如果您不想查看图像,字符 (°) 将替换为“..”。

enter image description here

最佳答案

问题是我的 R 语言环境是“C”。通过将其更改为另一个选项(中文):

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

然后重新启动 RConsole,它运行良好。

关于r - Theme() 不适用于 ggplot2 Unicode 显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52155913/

相关文章:

R_Multiple 使用 for 循环绘制同一图形

r - 如何在 fiddle 图上显示 mustache 和点?

python - 将 Python 3 Unicode 字节字符串 - `str(utf8_encoded_str)` 转换回 unicode

r - 如何按名称调用 R 函数内的 data.frame

r - 登录网站以使用 RCurl 获取数据

r - 使用R和ggplot2绘制金字塔图

r - dplyr Mutate 中的错误 - 遍历列以生成图形

r - st_normalize.sfc(x, c(x_range[1], y_range[1], x_range[2], y_range[2])) 中的错误 : domain must have a positive range

python - 正则表达式和 unicode 的问题

python - 如何使用 Python 从 unicode 字符串中切片子字符串?