用表达式分割轴标签 [英] Splitting axis labels with expressions

查看:146
本文介绍了用表达式分割轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含表达式的长标签,我想将它分成两行。
在表达式内添加\\\
,结果不符合预期。


$ b $ pre $ ylabel < - 表达式(一个包含文本和\ $​​
表达式的非常长的标签*(alpha + beta)[ij] *带文本和表达式的非常长的标签)
曲线(x ^ 3 - 3 * x,-2,2,xlab = xlabel)

任何帮助将不胜感激。谢谢

解决方案

这是另一种解决方案,依靠 atop AndresT在他的编辑。
请注意,我们不能在表达式中使用控制字符,例如 \\\
,这就解释了为什么使用类似于表达式(paste(。 .. \\\
,alpha [i],....))
不会产生所需的输出。 ($)$表达式(atop(一个非常长的带有文本和表达式的标签,
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆