用表达式分割轴标签 [英] Splitting axis labels with expressions
问题描述
我有一个包含表达式的长标签,我想将它分成两行。
在表达式内添加\\\
,结果不符合预期。
$ b $ pre $
ylabel < - 表达式(一个包含文本和\ $
表达式的非常长的标签*(alpha + beta)[ij] *带文本和表达式的非常长的标签)
曲线(x ^ 3 - 3 * x,-2,2,xlab = xlabel)
任何帮助将不胜感激。谢谢
这是另一种解决方案,依靠 atop
AndresT在他的编辑。
请注意,我们不能在表达式中使用控制字符,例如 \\\
,这就解释了为什么使用类似于
表达式(paste(。 .. \\\
不会产生所需的输出。 ($)$表达式(atop(一个非常长的带有文本和表达式的标签,
,alpha [i],....))
paste((alpha + beta)[ij],一个非常长的标签... )))
curve(x ^ 3 - 3 * x,-2,2,sub = xlabel,xlab =)
请注意,我使用 sub
而不是 xlab
来避免与x勾号。
I have a plot with a long label containing an expression and I want to split it on two lines.
Adding a "\n" inside the expression the result is not as expected.
ylabel <- expression("A very long label with text and \n
expression"*(alpha+beta) [ij]*" A very long label with text and expression")
curve(x^3 - 3*x, -2, 2, xlab=xlabel)
Any help would be appreciated. Thanks
Here is another solution, relying on atop
as did @AndresT in his edit.
Note that we cannot use control character like \n
in an expression, which explains why using something like expression(paste("...\n", alpha[i], "...."))
would not produce the desired output.
xlabel <- expression(atop("A very long label with text and expression",
paste((alpha+beta)[ij], " A very long label ...")))
curve(x^3 - 3*x, -2, 2, sub=xlabel, xlab="")
Note that I used sub
instead of xlab
to avoid collision with x tick marks.
这篇关于用表达式分割轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!