带下标的 Unicode 字符
Unicode character with subscript
我想在我的 R 绘图图例中添加一个 Unicode 字符,它有两个字母作为下标。
该字符是带有短音符 (ř) 的 r,两个字母是 i 和 j。
我已经看过这个问题:Unicode character with superscript 并尝试根据我的问题调整答案。
这是我尝试过的:
plot(1,pch=NA,ylab="",xlab="",axes=F)
legend("top",legend=paste("1-","\u{0159}"),bty ="n",bg = "white",cex=2)
legend("center",legend=paste("1-","\u{0159}","\u{0069}","\u{006A}"),bty="n",bg = "white",cex=2)
legend("bottomleft",legend=expression("1-"*"\u0159"["\u0069"*"\u006A"]),bty="n",bg = "white",cex=2)
legend("bottomright", legend = quote("1-" *"\u0159"["\u0069"*"\u006A"]),bty="n",bg = "white",cex=2)
生成的图可以在下面找到
Unicode 字母和下标都可以单独使用,但不能一起使用。
paste() 与 [ ] 的任意组合都会 return 出错,但我认为这是可以预料的,因为 paste 无法处理下标的 [ ]。
CRAN 上的常见问题解答网站可能会给我一些提示,因为我正在使用 Windows,但我不确定如何实施:
3.6 I don't see characters with accents at the R console, for example in ?text.
You need to specify a font in Rconsole (see Q5.2) that supports the encoding in use. This used to be a problem in earlier versions of Windows, but now it is hard to find a font which does not.
Support for these characters within Rterm depends on the environment (the terminal window and shell, including locale and codepage settings) within which it is run as well as the font used by the terminal window. Those are usually on legacy DOS settings and need to altered.
这与系统语言环境有关,例如如果你尝试
# intToUtf8(345)
# [1] "ř"
# iconv(intToUtf8(345), "utf-8", localeToCharset())
# [1] "r"
这应该可以修复它(我使用的是捷克语,但其他语言环境也可能有效):
Sys.setlocale("LC_CTYPE", "czech")
# [1] "Czech_Czech Republic.1250"
text(..., labels = quote("\u{0159}"[ij]))
我想在我的 R 绘图图例中添加一个 Unicode 字符,它有两个字母作为下标。 该字符是带有短音符 (ř) 的 r,两个字母是 i 和 j。
我已经看过这个问题:Unicode character with superscript 并尝试根据我的问题调整答案。
这是我尝试过的:
plot(1,pch=NA,ylab="",xlab="",axes=F)
legend("top",legend=paste("1-","\u{0159}"),bty ="n",bg = "white",cex=2)
legend("center",legend=paste("1-","\u{0159}","\u{0069}","\u{006A}"),bty="n",bg = "white",cex=2)
legend("bottomleft",legend=expression("1-"*"\u0159"["\u0069"*"\u006A"]),bty="n",bg = "white",cex=2)
legend("bottomright", legend = quote("1-" *"\u0159"["\u0069"*"\u006A"]),bty="n",bg = "white",cex=2)
生成的图可以在下面找到
Unicode 字母和下标都可以单独使用,但不能一起使用。 paste() 与 [ ] 的任意组合都会 return 出错,但我认为这是可以预料的,因为 paste 无法处理下标的 [ ]。
CRAN 上的常见问题解答网站可能会给我一些提示,因为我正在使用 Windows,但我不确定如何实施:
3.6 I don't see characters with accents at the R console, for example in ?text.
You need to specify a font in Rconsole (see Q5.2) that supports the encoding in use. This used to be a problem in earlier versions of Windows, but now it is hard to find a font which does not.
Support for these characters within Rterm depends on the environment (the terminal window and shell, including locale and codepage settings) within which it is run as well as the font used by the terminal window. Those are usually on legacy DOS settings and need to altered.
这与系统语言环境有关,例如如果你尝试
# intToUtf8(345)
# [1] "ř"
# iconv(intToUtf8(345), "utf-8", localeToCharset())
# [1] "r"
这应该可以修复它(我使用的是捷克语,但其他语言环境也可能有效):
Sys.setlocale("LC_CTYPE", "czech")
# [1] "Czech_Czech Republic.1250"
text(..., labels = quote("\u{0159}"[ij]))