Search code examples
rexpressionplotmath

How to add >-sign to expression in R?


I'd like to add a "greater than"-sign to an axis label. The text shown should be cumulated frequency p(>p[f]))

I tried (amongst others):

title(mgp=c(2.50, 1, 0), cex.lab=1.25, xlab = expression("cumulated frequency" ~ p(>p[f]))) # xlab

But none of my trials worked - where is the mistake? Without having the > it works fine:

title(mgp=c(2.50, 1, 0), cex.lab=1.25, xlab = expression("cumulated frequency" ~ p(p[f]))) # xlab

Solution

  • > is a binary operator. Thus, it needs something on its left side. For example a "dummy"-null-label {}:

    plot(1:10, 1:10, xlab=expression("frequency"~p({}>p[f])))
    

    Also, e.g. phantom(), plain(), etc. may be used to print "nothing".

    If you don't want spaces around <, try:

    plot(1:10, 1:10, main=expression("test"~p(paste(">",p[f]))))
    

    or for a more "mathematical" <:

    plot(1:10, 1:10, main=expression("test"~p(paste(symbol(">"),p[f]))))