首页 > 解决方案 > Windows 10 上的 R 输出中缺少 Unicode 字符

问题描述

我在 Windows 10 上运行 R。

我在将 Unicode 符号显示为点的形状时遇到问题。(我试图在我的火山图(\u2B06,⬆)中放置一个向上箭头,以获取超出比例的点)。有些工作,有些不工作。 示例

TestUnicode <- function(start="25a0", end="25ff", ...)
{
  nstart <- as.hexmode(start)
  nend <- as.hexmode(end)
  r <- nstart:nend
  s <- ceiling(sqrt(length(r)))
  par(pty="s")
  plot(c(-1,(s)), c(-1,(s)), type="n", xlab="", ylab="",
       xaxs="i", yaxs="i")
  grid(s+1, s+1, lty=1)
  for(i in seq(r)) {
    try(points(i%%s, i%/%s, pch=-1*r[i],...))
 }
}

TestUnicode()
TestUnicode(9500,9900)

示例输出

在我的系统上,一些字符只是显示为空方框。

到目前为止,我了解到这是由 Windows 字体问题引起的,并且很可能是由 Windows 10 存储字体的新方式引起的。

我发现的大多数类似问题的解决方案都遗憾地适用于基于 Unix 的系统并使用:

Sys.setlocale( locale="UTF-8" )

我假设这是一个 Unix 命令,因为它给了我以下信息:

[1] ""
Warning message:
In Sys.setlocale(locale = "UTF-8") :
  OS reports request to set locale to "UTF-8" cannot be honored

我尝试了使用“showtext”包的解决方案,但不知何故,这也不起作用,Windows 10 可能再次成为麻烦制造者。(安装“诺托”)

    library(showtext)
    font_paths()
[1] "C:\\Windows\\Fonts"
    font_add(family="Noto", regular="NotoSansSymbols-Regular.ttf")
    plot(1,1,pch='⬆',family='Noto')
There were 12 warnings (use warnings() to see them)
    warnings()
Warning messages:
1: In plot.xy(xy, type, ...) : font family not found in Windows font database

有没有人有办法解决吗 ?将不胜感激任何帮助<3

标签: runicodewindows-10

解决方案


推荐阅读