1

say I have the plot

plot(1:10,1:10)

and I want to add the y-axis label

'this is text where I write the variable', sigma^*, 'in my favorite units'

Sigma star should be as close to latex code $\sigma^*$ as possible.

I have tried ?mathplot, and tried googling but can only find answers where the expression is at the end of a string of text and opposed to sandwiching the expression in-between text. Hence this is not a duplicate of the thread. I've tried doing things like expression(paste(...)) but that has not worked.

Community
  • 1
  • 1
WetlabStudent
  • 2,556
  • 3
  • 25
  • 39

1 Answers1

2

A call to bquote should work for you:

plot(1:10,1:10,ylab=bquote("this is text where I write the variable" ~ sigma^"*" ~ "in my favorite units"))

enter image description here

Also, as we discussed in comments, if you are unhappy with the shape of the asterisk created by bquote your options are somewhat limited... My best guess for a simple solution would be to switch to another font, like so:

plot(1:10,1:10,ylab=bquote("this is text where I write the variable" ~ sigma^symbol("*") ~ "in my favorite units"))

enter image description here

or to draw the aterix symbol without putting it in exponent, but then you start to be far away from the latex rendering of $\simga\^{*}$:

plot(1:10,1:10,ylab=bquote("this is text where I write the variable" ~ sigma ~ "*" ~ "in my favorite units"))

enter image description here

Do this help?

Jealie
  • 6,157
  • 2
  • 33
  • 36
  • This is close, but the expression part ~ sigma^"*" ~ overlaps some of the rest of the text. I tried throwing a \n in there but alignment isn't quite right if I do that. Also the star seems really high in the superscript, I'd prefer something a bit lower. – WetlabStudent Apr 18 '14 at 04:05
  • I am not sure I understand what you are talking about... I added a picture to show how it is rendered on my side: it looks alright to me. – Jealie Apr 18 '14 at 04:09
  • For me sigma is placed right on top of the "le" in variable – WetlabStudent Apr 18 '14 at 04:12
  • You should try to copy and paste exactly the expression, in a new R session - if it still doesn't work, it may be relevant to file a bug report... somewhere... – Jealie Apr 18 '14 at 04:16
  • OK ... also is there anyway to get the star lower than that? – WetlabStudent Apr 18 '14 at 04:21
  • for example if you add a \n between "the" and "variable" the "*" is so high that R refuses to place it directly below the first line because it would collide with it. – WetlabStudent Apr 18 '14 at 04:26
  • 1
    I am guessing that it is finally working then? You can also have a better result by switching to the `symbol` font for the asterisk. I am updating the answer in a moment.. – Jealie Apr 18 '14 at 15:16