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:
$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)")))
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
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:
It isn't immediately clear from your Q which one is preferable.
精彩评论