在绘图中将普通文本与普通文本结合使用
更新:我实际上自己找到了解决方案,见下文。
在 RI 中,想要向包含下标和普通文本的绘图添加标签。更准确地说,我想使用 mtext() (或任何其他可以实现这一点的方法)在绘图下方添加文本。文本应如下所示:
这可以在乳胶中轻松完成,在 RI 中使用 $B\pm t_{a/2}SE(B)$
达到 mtext(expression(B%+-%t[a /2]))
,它确实打印
但困难在于获得 SE(B ) 后面的部分,因为表达式处理SE(B) 作为函数。我尝试了几种与粘贴的组合,但没有成功。我确信一定有一个简单的解决方案来解决这个问题,但经过很长时间的搜索后我找不到一个解决方案。
更新:
哇,我自己找到了解决方案。正如我所说,我尝试过表达和粘贴的组合,并且确信我以前尝试过,但显然我没有。解决方案是这样的:
mtext(expression(paste(B%+-%t[a/2],"SE(B)")))
UPDATE: I actually found the solution myself, see below.
In R I want to add a label to a plot containing both subscript and normal text. To be more precise, I would like to use mtext() (or any other method that does the trick) to add a text below a plot. The text should look like this:
This can easily done in latex with $B\pm t_{a/2}SE(B)$
In R I come as far as mtext(expression(B%+-%t[a/2]))
, which does print
But the difficulty is in geting the SE(B) part after it, because of expression treating SE(B) as a function. I've tried several combinations with paste, but to no avail. I'm sure there must be a simple solution to this, but I wasn't able to find one after quite a long search.
UPDATE:
Wow, found the solution myself. As I said I have tried combinations of expression and paste and was sure I tried this before, but apparently, I did not. The solution is this:
mtext(expression(paste(B%+-%t[a/2],"SE(B)")))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到您已经解决了这个问题,但是您的最终解决方案通过删除
paste()
的使用并使用~
运算符添加间距来处理得更好、更简洁:例如:
给出
您可以使用多个
~
添加额外的间距:~~~
例如。如果您只想并置方程的两个部分,请使用*
运算符,如下所示:给出:
从您的问题中并不能立即清楚哪一个更可取。
I see you have solved this, but your final solution is much more nicely and succinctly handled by dropping the use of
paste()
and using the~
operator to add spacing:e.g.:
which gives
You can add extra spacing by using multiple
~
:~~~
for example. If you just want to juxtapose two parts of an equation, using the*
operator, as in:which gives:
It isn't immediately clear from your Q which one is preferable.