2

This is a follow up question to "Displaying a greater than or equal sign"

This is the text I wish to display as the y axis label: Pr(Number of Invasions, X ≥ x)

This is the code:

expression(paste("Pr(Number of Invasions,  ", italic('X'), "\u2265", italic('x'), ")"))

What I get is: Pr(Number of Invasions, X = x)

This is the same result in the thread mentioned above. "\u2265" is supposed to overcome the issue, as suggested in the answers to the thread but it doesn't in my case.

When I run "\u2265" the result is:

"\u2265"
[1] "≥"

When I assign this to an object I get the same result:

symbol<-"\u2265"
symbol
[1] "≥"

However, in the Global Environment the object "symbol" contains "=".

Can anyone suggest how to display the symbol in the plot? The answer isn't obvious to me.

I'm using RStudio, and OS system is Windows 7

Community
  • 1
  • 1
Jason Axford
  • 67
  • 1
  • 6
  • 1
    Can you add your OS please ... symbol renders using ubuntu14.04 – user20650 May 22 '15 at 03:04
  • OS system is Windows 7. – Jason Axford May 22 '15 at 03:05
  • What does "Global Environment the object 'symbol' contains '='" mean exactly? Is the 'symbol' you are showing us not in the global environment? And what does that variable have to do with the plotmath anyway? A [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) would be helpful here. – MrFlick May 22 '15 at 03:09
  • And does `plot(1,1, main=expression("Pr"~(list("Number of Invasions",X>=x))))` work for you? – MrFlick May 22 '15 at 03:12
  • Yes, that displays the symbol. I think I see the problem. The issue is I'm formatting the Xs as italic so that expression doesn't evaluate >= properly. – Jason Axford May 22 '15 at 03:22
  • I've you've solved your own problem, put it as an answer to close out the question and to help others in the future. – MrFlick May 22 '15 at 03:49

2 Answers2

4

By placing quotations marks around >= or \u2265 within paste within expression, it is was not able to produce the right symbol. Even though I was formatting the Xs in italics, I should have just treated the code as if it was X>=x, which is what expression really wants to see, as MrFlick suggested... which makes sense now. So:

expression(paste("Pr(Number of Invasions", italic('X')>=italic('x'), ")"))

Thanks MrFick!

Jason Axford
  • 67
  • 1
  • 6
  • 2
    It is simply untrue that you cannot get `'\u2265'` to produce a .GE. symbol inside a plotmath paste expression (at least assuming the unicode value maps to that character in your installed font). Use: `expression(paste(italic(X),'\u2265',italic(x) ) ` – IRTFM May 22 '15 at 08:22
1

You don't need paste. It's often clearer to use ~ and * as separators

plot(1,1, xlab=expression(Pr*'('*Number~of~Invasions~~ italic(X)*'\u2265'*italic(x)*")")  )

That way it's easier to transition to the "full" plotmath version which gets a different spacing and looks better:

plot(1,1,
      xlab=expression( Pr*'('*Number~of~Invasions~~ italic(X) >= italic(x)*")" )
     )

If you had really wanted to have a named token hold the "≥" character, you can use the bquote and .( )-functions. The names inside the .( ) get evaluated (when the dot-function is within bquote):

symbol<-"\u2265"
plot(1,1,xlab=bquote(Pr*'('*Number~of~Invasions~~ italic(X) * .(symbol) * italic(x)*")") )
IRTFM
  • 258,963
  • 21
  • 364
  • 487