在绘图中将普通文本与普通文本结合使用

发布于 2024-12-07 05:19:56 字数 646 浏览 0 评论 0原文

更新:我实际上自己找到了解决方案,见下文。

在 RI 中,想要向包含下标和普通文本的绘图添加标签。更准确地说,我想使用 mtext() (或任何其他可以实现这一点的方法)在绘图下方添加文本。文本应如下所示:

The label
这可以在乳胶中轻松完成,在 RI 中使用 $B\pm t_{a/2}SE(B)$

达到 mtext(expression(B%+-%t[a /2])),它确实打印

r so far

但困难在于获得 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:

The label

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

r so far

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼趣 2024-12-14 05:19:57

我看到您已经解决了这个问题,但是您的最终解决方案通过删除 paste() 的使用并使用 ~ 运算符添加间距来处理得更好、更简洁:

expression(B %+-% t[a/2] ~ SE(B))

例如:

plot(1:10, xlab = expression(B %+-% t[a/2] ~ SE(B)))

给出

在此处输入图像描述

您可以使用多个 ~ 添加额外的间距: ~~~ 例如。如果您只想并置方程的两个部分,请使用 * 运算符,如下所示:

plot(1:10, xlab = expression(B %+-% t[a/2] * SE(B)))

给出:

在此处输入图像描述

从您的问题中并不能立即清楚哪一个更可取。

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:

expression(B %+-% t[a/2] ~ SE(B))

e.g.:

plot(1:10, xlab = expression(B %+-% t[a/2] ~ SE(B)))

which gives

enter image description here

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:

plot(1:10, xlab = expression(B %+-% t[a/2] * SE(B)))

which gives:

enter image description here

It isn't immediately clear from your Q which one is preferable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文