I'm using expression()
in R plots in order to get italicized text. But it appears as if I cannot use Unicode symbols inside expression
outside of ASCII characters. 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).
我在R图中使用expression()来获得斜体文本。但似乎我不能在ASCII字符以外的表达式中使用Unicode符号。有什么办法可以解决这个问题吗?我的目标是在我的R条形图(连同斜体文本)中获得不同标签中的fi连接。
I'm using R for Windows version 3.0.2.
我用R表示Windows 3。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()
1 个解决方案
#1
3
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.
你要求工作。这就是全部。斜体部分需要表达式,而“fi”部分不需要,所以要分别打印。
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".
但是请注意,“fi”的间距有些不对,所以当我在屏幕上计算宽度时,我作弊并计算了“fi”的宽度(有额外的空白)。如果没有额外的间隔,第二个斜体(m)与“fi”重叠。
Not pretty, but it produces the desired result under Windows.
不是很好,但是它在Windows下生成了想要的结果。
#1
3
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.
你要求工作。这就是全部。斜体部分需要表达式,而“fi”部分不需要,所以要分别打印。
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".
但是请注意,“fi”的间距有些不对,所以当我在屏幕上计算宽度时,我作弊并计算了“fi”的宽度(有额外的空白)。如果没有额外的间隔,第二个斜体(m)与“fi”重叠。
Not pretty, but it produces the desired result under Windows.
不是很好,但是它在Windows下生成了想要的结果。