开发者

Used normal text in combination with normal text in plot

开发者 https://www.devze.com 2023-04-09 18:32 出处:网络
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

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 p开发者_开发知识库lot. The text should look like this:

Used normal text in combination with normal text in plot

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

Used normal text in combination with normal text in plot

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)")))


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

Used normal text in combination with normal text in plot

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:

Used normal text in combination with normal text in plot

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号