Unicode character with subscript
I want to add a Unicode character which has two letters as subscripts to my plot legend in R. The character is an r with an accent breve (ř) and the two letters are i and j.
I already looked at this question: Unicode character with superscript and tried to adapt the answers to my problem.
Here is what I tried:
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)
The resulting plot can be found below
Both the Unicode letter and the subscript work fine by themselves but not together. paste() with any combination of [ ] does return an error, but I think this is to be expected as paste can't handle [ ] for subscripts.
The FAQ site on CRAN might give a hint as I am using Windows but I am not sure how to implement this:
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.
It has to do with the system locale, as seen eg if you try
# intToUtf8(345)
# [1] "ř"
# iconv(intToUtf8(345), "utf-8", localeToCharset())
# [1] "r"
This should fix it (I used Czech but other locales will probably work too):
Sys.setlocale("LC_CTYPE", "czech")
# [1] "Czech_Czech Republic.1250"
text(..., labels = quote("u{0159}"[ij]))
链接地址: http://www.djcxy.com/p/25238.html
上一篇: this.someFunction.call的用途是什么(this,param);
下一篇: 带下标的Unicode字符