简体   繁体   English

在R的expression()命令中使用Unicode

[英]Using Unicode inside R's expression() command

I'm using expression() in R plots in order to get italicized text. 我在R绘图中使用expression()以获得斜体文本。 But it appears as if I cannot use Unicode symbols inside expression outside of ASCII characters. 但是似乎我无法在ASCII字符之外的expression内使用Unicode符号。 Is there some way I can work around this? 有什么办法可以解决这个问题? My goal is to get the fi ligature in various labels in my R barplots (together with italicized text). 我的目标是让fi中的各种标签结扎在我的[R barplots(用斜体文字一起)。

I'm using R for Windows version 3.0.2. 我将R用于Windows版本3.0.2。

CairoPDF(file = "Ligature1.pdf")
plot.new()
text(x =.5, y = .5, labels = "fi", family = "Times New Roman")
dev.off()

在此处输入图片说明

CairoPDF(file = "Ligature2.pdf")
plot.new()
text(x =.5, y = .5, labels = expression(paste(italic(m), "u", "fi", italic(m), sep = "")), family = "Times New Roman")
dev.off()

在此处输入图片说明

You asked for a work-around. 您要求解决方法。 That is all this is. 这就是全部。 The italic part needs expression , but the "fi" part does not, so print them separately. 斜体部分需要expression ,而“?”部分则不需要,因此请分别打印。

plot.new()
offset1 = strwidth(expression(paste(italic(m), "u")), units="figure")
text(x =.5, y = .5, labels = expression(paste(italic(m), "u", sep="")))
text(x =.5+offset1, y = .5, labels ="fi")
offset2 = strwidth("fi ")
text(x =.5+offset1+offset2, y = .5, labels = expression(italic(m)))

格式化输出

But notice that something is not quite right about the spacing of the "fi", so when I computed the width on the screen, I cheated and computed the width of "fi " (with an extra blank). 但是请注意,“?”的间距不太正确,因此当我计算屏幕上的宽度时,我作弊并计算了“?”的宽度(带有额外的空白)。 Without the extra spacing, the second italic(m) overlapped the "fi". 没有多余的间距,第二个italic(m)与“?”重叠。

Not pretty, but it produces the desired result under Windows. 不漂亮,但是在Windows下可以产生理想的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM